选项1:在数据库中插入数据
SqlCommand cmd = new SqlCommand("INSERT INTO table_name(eid,eName,Dept) values('"+ textBox1.Text +"','"+ textBox2.Text +"','"+ Textbox3.Text +"'", con);
cmd.ExecuteNonQuery();
选项 2:
SqlDataAdapter sqlda = new SqlDataAdapter("SELECT * FROM table_name",con);
SqlCommandBuilder sqlcomb = new SqlCommandBuilder(sqlda);
DataSet dset = new DataSet("table1");
sqlda.Fill(dset,"table1");
DataRow drow = dset.Tables["table1"].NewRow();
drow["eid"] = textBox1.Text.ToString();
drow["eName"] = textBox2.Text.ToString();
drow["Dept"] = textBox3.Text.ToString();
dset.Tables["table1"].Rows.Add(drow);
sqlda.Update(dset, "table1");
我的问题是,我觉得 option1 是最好的插入方法。为什么我们使用SqlCommandBuilder
插入数据?SqlCommandBuilder 有什么用?使用插入数据有什么好处SqlCommandBuilder
?你的建议