WHEN MY WEBSITE USERS CICK A BUTTON A NEW TABLE IN MY EXISTING DATABASE SHOULD BE CREATED.
I USE THE BELLOW CODE BUT IT DOES NOT WORKS AND NO NEW TABLE IS CREATING.
PLEASE SUGGEST ME IF I AM WRONG SOMEWHERE.
THANK YOU
I AM USING THIS CODE IN BUTTON CLICK EVENT
protected void Button7_Click(object sender, EventArgs e)
{
string cs = WebConfigurationManager.ConnectionStrings["LocalSqlServer"].ConnectionString;
SqlConnection con = new SqlConnection(cs);
string sqlStatement = "CREATE TABLE dbo.prince (stuname CHAR(50), stuaddress CHAR(255), stubalance FLOAT)";
SqlCommand sqlCmd = new SqlCommand(sqlStatement, con);
sqlCmd.ExecuteNonQuery();
con.Close();
}
Anita SrivastavPosted Nov 23, 2013, 8:46 AM
acttually i am working on asp.net and C# and u r suggesting me for windows form and i also used this logic but it is not helping try anything else dear
Anita SrivastavPosted Nov 23, 2013, 8:42 AM
no i dont get any error but in my databse no new table is creating.
Satyapriya NayakPosted Nov 23, 2013, 8:26 AM
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
using System.Web.Configuration;
namespace Insert_data_confirmation
{
public partial class WebForm5 : System.Web.UI.Page
{
protected void Button1_Click(object sender, EventArgs e)
{
string cs = WebConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
SqlConnection con = new SqlConnection(cs);
con.Open();
string sqlStatement = "CREATE TABLE dbo.prince (stuname CHAR(50), stuaddress CHAR(255), stubalance FLOAT)";
SqlCommand sqlCmd = new SqlCommand(sqlStatement, con);
sqlCmd.ExecuteNonQuery();
con.Close();
}
}
}
Satyapriya NayakPosted Nov 23, 2013, 8:18 AM
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
namespace Insert
{
public partial class WebForm5 : System.Web.UI.Page
{
string strConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(strConnString);
con.Open();
string sqlStatement = "CREATE TABLE dbo.prince(stuname CHAR(50), stuaddress CHAR(255), stubalance FLOAT)";
SqlCommand sqlCmd = new SqlCommand(sqlStatement, con);
sqlCmd.ExecuteNonQuery();
con.Close();
}
}
}
Rakesh KalluriPosted Nov 23, 2013, 8:08 AM