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]

Vishnujeet KumarPosted Nov 5, 2012, 10:29 PM
in your code you passing table name and respected value that is good but after passing value,
you adding one string ')' in sql query that is wrong ,it's query syntax error.