5
Answers

create table dynamically using asp.net C#

 I WANT TO CREATE A NEW TABLE IN AN EXISTING DATABASE.
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();                     
    }
Answers (5)