I need to insert data using dataAdapter. I have using following code. Isthis code iscorrect or nt??
<<<<<<<<<<<<<<<<<<
private void btnSave_Click(object sender, EventArgs e)
{
SqlConnection cn;
string cnstring = "server=(local)\\SQLEXPRESS;Database=Test;Integrated Security=True";
cn = new SqlConnection(cnstring);
string sql;
sql = "insert into Insert1 values('" + txtname.Text + "'," + txtrno.Text + ",'" + txtadd.Text + "','" + cmdgender + "')";
cn.Open();
SqlDataAdapter da = new SqlDataAdapter(sql, cn);
cn.Close();
}
>>>>>>>>>>>>>>>>
DataAdapter Code
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.

Amit ChoudharyRank #145 · 15.8K reputationPosted Mar 9, 2010, 9:36 PM EST
To update or insert using adapter is used with datasets and datatables.
for simple insert statement can be executed using SqlCommand object.
SqlCommand cmd=new SqlCommand(cn); cmd.Text= "insert into Insert1 values('" + txtname.Text + "'," + txtrno.Text + ",'" + txtadd.Text + "','" + cmdgender + "')"; int result=cmd.ExecuteNonQuery(); cn.close();Hope it helps you.
Please mark it as answer and let me know if it helps you.
VasanthRank #1,487 · 1.1K reputationPosted Mar 9, 2010, 11:12 PM EST
SqlDataAdapter da = new SqlDataAdapter();
da.InsertCommand = new SqlCommand (
......insert input values in datarow.......
da.update(
No need to use commandbuilder here.