Shourya Verdhan

Shourya Verdhan

  • NA
  • 88
  • 56.1k

How to insert values in table when table name comes from textboxid using window form

Nov 3 2012 9:26 PM
Dear Friends,

i have a code where i insert values in table and  table name comes from textbox id 

Code is...



                SqlConnection con = new SqlConnection();
                con.ConnectionString = "data source=NDTS12; initial Catalog=ndts_tm247; integrated security=true;";
                con.Open();
                string sql = "INSERT INTO " + txtemployeeid.Text.Trim() + "values('" + txtname.Text + "','" + txtcont.Text + "','" + txtcont2.Text + "','" + txtaddress.Text + "','" + txtmail.Text + "','" + txtsaletype.Text + "','" + txtamount.Text + "','" + dateTimePicker1.Text + "','" + txtissue.Text + "','" + txtstatus.Text + "','" + txttechname.Text + "','" + txtos.Text + "','" + txttvid.Text + "','" + txttvpw + "','" + txtdiscription.Text + "' )";  sql += ")";
               

                SqlCommand cmd = new SqlCommand(sql, con);
                cmd.ExecuteNonQuery();
                con.Close();


But this code Generate an exception new  "' )";  sql += ")"; 
any one can tell AS SOON AS POSIBLE me where is the problem in this code
my email id is [email protected]

Answers (1)