C#新手,关于bindingnavigator中添加一个SaveButton保存的问题?
我用的VS2008,在winform中,拖入控件datagridview1,bindingnavigator1,并在bindingnavigator中设置了一个textbox1和一个button1,
代码如下,已经可以实现在textbox1中搜索并把结果在dataGridView1中显示:
private void button1_Click(object sender, EventArgs e)
{
//String ConnectionString = global::LogisticsInfoSys.Properties.Settings.Default.ConnectionString;
//SqlConnection MyConnection = new SqlConnection(conn);
SqlConnection conn = BaseClass.DBConn.MainConn();
conn.Open();
string MySQL = "Select * From tb_Master Where iCarOrder LIKE '" + this.textbox1.Text + "'";
DataTable MyMsaterTable = new DataTable();
SqlDataAdapter tb_MasterTableAdapter = new SqlDataAdapter(MySQL, conn);
tb_MasterTableAdapter.Fill(MyMsaterTable);
this.dataGridView1.DataSource = MyMsaterTable;
if (conn.State == ConnectionState.Open)
{
conn.Close();
}
}
问题是,我想在bindingnavigator中又添加一个SaveButton,想实现datagridview中直接修改数据后保存,在MSDN官方上的解决答案是如下代码:
private void SaveButton_Click(System.Object sender,
System.EventArgs e)
{
TableAdapterName.Update(DataSetName.TableName);
}
如它的格式我试了N次,我几天都搞不定,请能帮助我。谢谢!!