在winforms中编辑值

本文关键字:编辑 winforms | 更新日期: 2023-09-27 18:09:11

有人能告诉我如何从我的winforms编辑值并将其保存在数据库中吗?

我已经编写了这段代码,但是当我执行代码时,文本框中出现了slipNo值,但没有任何编辑或任何事情发生:

string connectionString = "Data Source=TANYA-PC;Initial Catalog=biore1;Integrated Security=True";
string sql = "SELECT * FROM cottonpurchase";
SqlConnection connection = new SqlConnection(connectionString);
SqlDataAdapter da = new SqlDataAdapter(sql, connection);
DataSet ds = new DataSet();
connection.Open();
da.Fill(ds, "cottonpurchase");
connection.Close();
// create the BindingSource
BindingSource bsCottonPurchase = new BindingSource();
bsCottonPurchase.DataSource = ds.Tables["cottonpurchase"];
// bind the grid            
dataGridView1.DataSource = bsCottonPurchase;
// And bind the TextBoxes
this.TxtSlipNo.DataBindings.Add("Text", bsCottonPurchase, "slipNo");
enableDisableControls(false);

在winforms中编辑值

您需要定义SqlDataAdapter。UpdateCommand并调用DbDataAdapter.Update.