更新windows窗体中的gridview行c# [英] update gridview row in windows form c#
本文介绍了更新windows窗体中的gridview行c#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
iam尝试使用gridview单元更新sql值
我已经完成了一半,即只有一个参数Reject正在工作但是在尝试第二个参数时不会得到更新。
请在代码中制作chnges。
thx提前全部... < br $>
iam try to update sql value using gridview cell
half i have done,i.e only one parameter of "Reject " is working but when trying fro second parameter its wont get update.
pls make chnges in code.
thx in advance all...
private void button1_Click(object sender, EventArgs e)
{
if (objConn1.State != ConnectionState.Open)
{
objConn1.Open();
}
for (int i = 0; i < dataGridView1.SelectedRows.Count; i++)
{
DialogResult result;
result = MessageBox.Show("Are You sure want to Update?", "Conformation", MessageBoxButtons.YesNo);
if (result == System.Windows.Forms.DialogResult.Yes)
{
//string sql = "update [SAPProduction].[ProductionData] set Rejection " + " Where id = '" + dataGridView2.CurrentRow.Cells["id"].Value.ToString() + "' ";
// Jobcard = your desire Rows Jobcard Id
SqlCommand command = new SqlCommand("UPDATE SAPProduction.ProductionData SET Rejection,Remark = @Reject,@Remark Where id = '" + dataGridView1.CurrentRow.Cells["id"].Value.ToString() + "' ", objConn1);
command.Parameters.AddWithValue("@Reject",dataGridView1.CurrentRow.Cells["Rejection"].Value.ToString());
command.Parameters.AddWithValue("@Remark",dataGridView1.CurrentRow.Cells["Remark"].Value.ToString());
command.ExecuteNonQuery();
MessageBox.Show("Row Updated...");
objConn1.Close();
}
}
}
推荐答案
你应该试试这段代码而不是你的代码。
you should try this code instead of your code.
SqlCommand command = new SqlCommand("UPDATE SAPProduction.ProductionData SET Rejection=@Reject,Remark=@Remark Where id = '" + dataGridView1.CurrentRow.Cells["id"].Value.ToString() + "' ", objConn1);
SqlCommand command = new SqlCommand(UPDATE SAPProduction.ProductionData SET Rejection = @ Reject,Remark = @ Remark where id ='+ dataGridView1.CurrentRow.Cells [id]。Value.ToString()+',objConn1);
SqlCommand command = new SqlCommand("UPDATE SAPProduction.ProductionData SET Rejection=@Reject,Remark=@Remark Where id = '" + dataGridView1.CurrentRow.Cells["id"].Value.ToString() + "' ", objConn1);
这篇关于更新windows窗体中的gridview行c#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文