本文介绍了将GridView数据更新为SQL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 嗨朋友们, 我正在使用C #Windows Application.I我正在使用for循环Condition.Iow将数据显示到网格视图中,我想将数据(在datagridview中显示)更新为SQL数据库......但它没有显示新添加的数据... 这里是我的示例代码在网格中显示数据.... Hi Friends, I am using C# Windows Application.I am displaying SQL data into grid view using for loop Condition.Now, I want to update data(which is display in datagridview) into SQL Database...But it didn't display the newly added data...here is my sample code Display data in Grid....comm = "select Name,Rate,Qty,TotalAmount from SALESENTRY where PENo = '" + txt_VocherNo.Text + "'"; SqlCommand sqlcom = new SqlCommand(comm, sqlcon); SqlDataReader read = sqlcom.ExecuteReader(); if (read.HasRows) { int k = 0; while (read.Read()) { dgv_Entry.Rows[k].Cells["ColumnName"].Value = read.GetString(0); dgv_Entry.Rows[k].Cells["ColumnRate"].Value = read.GetString(1); dgv_Entry.Rows[k].Cells["ColumnRQty"].Value = read.GetString(2); dgv_Entry.Rows[k].Cells["ColumnTotal"].Value = Total; k++; } } sqlcon.Close(); 及其MY Update代码.. And its MY Update Code..if (btn_save.Text.Trim() == "&Update") { for (int no = 0; no <= dgv_Entry.Rows.Count - 1; no++) { if (dgv_Entry.Rows[no].Cells["ColumnName"].Value.ToString() == "" || dgv_Entry.Rows[no].Cells["ColumnName"].Value.ToString() == null) { break; } else { VNo = txt_VocherNo.Text; Name = dgv_Entry.Rows[no].Cells["ColumnName"].Value.ToString(); SRate = dgv_Entry.Rows[no].Cells["ColumnRate"].Value.ToString(); RQty = dgv_Entry.Rows[no].Cells["ColumnRQty"].Value.ToString(); Total = dgv_Entry.Rows[no].Cells["ColumnTotal"].Value.ToString(); Cmmd = "Update SALESENTRY Set Name = '" + Name + "',SRate ='" + Rate + "',RQty='" + Qty + "',Total='" + TotalAmount + "' Where Vno = '"+Vno+"' DbCon.SetDataBase(Cmmd); } } MessageBox.Show("Record Updated", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information); 现在如何更新新添加的记录旧的 例如。,我已经有4条记录了,现在我想用更新按钮添加一条记录。如何更新?.. 请建议... Now How can i update Newly Added record Instead of OldFor Example.,I have Already 4 Records, now i want to Add one More Record using Update Button..How can i update?..Please Suggest...推荐答案 这篇关于将GridView数据更新为SQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-29 02:56