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();
}
>>>>>>>>>>>>>>>>
Loading
VasanthPosted Mar 10, 2010, 4:12 AM
SqlDataAdapter da = new SqlDataAdapter();
da.InsertCommand = new SqlCommand (
......insert input values in datarow.......
da.update(
No need to use commandbuilder here.
Amit ChoudharyPosted Mar 10, 2010, 2:36 AM
To update or insert using adapter is used with datasets and datatables.
for simple insert statement can be executed using SqlCommand object.
Hope it helps you.
Please mark it as answer and let me know if it helps you.