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();
}

Rakesh KalluriRank #535 · 4.5K reputationPosted Nov 23, 2013, 3:08 AM EST
Satyapriya NayakRank #47 · 31.5K reputationPosted Nov 23, 2013, 3:18 AM EST
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();
}
}
}
Satyapriya NayakRank #47 · 31.5K reputationPosted Nov 23, 2013, 3:26 AM EST
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();
}
}
}
Anita Srivastav21 reputationPosted Nov 23, 2013, 3:42 AM EST
no i dont get any error but in my databse no new table is creating.
Anita Srivastav21 reputationPosted Nov 23, 2013, 3:46 AM EST
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