4
Reply

insert error

PankaJ D

PankaJ D

Mar 8 2010 4:32 AM
2.5k





SqlConnection cn = new SqlConnection(MyConn.cnstring);
//string sql = "insert into Insert1 values(?,?,?,?,?)";

SqlCommand cmd ;
cmd = new SqlCommand("insert into Insert1 values(?,?,?,?,?)", cn);

cmd.Parameters.AddWithValue("sname", txtname.Text);
cmd.Parameters.AddWithValue("srno", txtrno.Text);
cmd.Parameters.AddWithValue("sdob", dob.Value);
cmd.Parameters.AddWithValue("sadd", txtadd.Text);
cmd.Parameters.AddWithValue("sgender", cmdgender.Text);
cn.Open();
cmd.ExecuteNonQuery();
cn.Close();



When I use this code folowing error will gererate
"Incorrect syntax near '?'."

Answers (4)