[英]Update database with values in DataGridView using C#
How can I update the values in the database with the values in the DataGridRow when the button is clicked?单击按钮时,如何使用 DataGridRow 中的值更新数据库中的值?
To be precise i want to change the text of column from "En cours" to "PRET" when i click the button准确地说,当我单击按钮时,我想将列的文本从“En cours”更改为“PRET”
public void ajoutercolonne()
{
DataGridViewButtonColumn btn = new DataGridViewButtonColumn();
btn.Name = "Validation";
btn.Text = "Prêt";
btn.UseColumnTextForButtonValue = true;
dataGridView2.Columns.Add(btn);
}
Use a ado.net request tu update here is a example:使用 ado.net 请求更新这里是一个例子:
SqlConnection conn = new SqlConnection("Server=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\Database.mdf;Trusted_Connection=True;
User Instance=yes");
conn.Open();
string sql2 = "UPDATE student SET moneyspent = " + ?????? + " WHERE id=" + studentIndex + ";";
SqlCommand myCommand2 = new.
SqlCommand(sql2, conn);
See slso here: https://www.c-sharpcorner.com/UploadFile/718fc8/save-delete-search-and-update-record-in-ado-net/在此处查看 slso: https : //www.c-sharpcorner.com/UploadFile/718fc8/save-delete-search-and-update-record-in-ado-net/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.