如何使用单击按钮更新每个gridview行并在数据库中更新 [英] how to update the each gridview rows with a single of click button and update in the database
问题描述
在Gridview记录如下
Roomno课程Roomno课程
11 MFA(下拉列表)21 EFA(下拉列表)
12 RM(下拉列表)22 REO(下拉列表)
13 SAC(下拉列表)23 PH2(下拉列表)
在下拉列表中所有当然是从数据库中检索并显示在所有下拉列表中。
满分6分Roomno假设用户想要更改特别三roomno。
例如Roomno 11,21,23课程已更改如下
11 PH1
21 ARPA
23 ECDIS
单击按钮我想更新。
我怎么能用csharp。
int i = 0 跨度>;
int j = 0 ;
con = new OleDbConnection( YourConnectionString ); // 您使用的是哪种连接
con.Open( );
while (i < dataGridView1.Rows.Count)
{
string str = 更新YourTableName set YourColumnName =' + dataGridView1.Rows [ 1 ]。Cells [i] .Value + < span class =code-string>'其中RommNo =' + dataGridView1.Rows [ 0 ]。Cells [i] .Value + '; // 您更新查询
cmd = new OleDbCommand(str(),con);
cmd.ExecuteNonQuery();
i + = 1 ;
}
i = 0 ;
while (i < DataGridView1.Rows.Count)
{
str()= 更新YourTableName设置YourColumnName =' + dataGridView1.Rows [ 3 ]。Cells [i] .Value + '其中RommNo = ' + dataGridView1.Rows [ 2 ]。Cells [i] .Value + '; // 您的更新查询
cmd = new OleDbCommand(str(),con);
cmd.ExecuteNonQuery();
i + = 1 ;
}
您是否正在寻找类似的东西。
在Gridview中批量编辑更新删除 [ ^ ]
问候......:笑:
In Gridview Records as follows
Roomno Course Roomno Course
11 MFA(dropdownlist) 21 EFA(dropdownlist)
12 RM(dropdownlist) 22 REO(dropdownlist)
13 SAC(dropdownlist) 23 PH2(dropdownlist)
In dropdownlist all the course are retrieve from the database and displayed in the all the dropdownlist.
Out of 6 Roomno suppose user want to change the Particular three roomno.
For example Roomno 11,21,23 Course has changed as follows
11 PH1
21 ARPA
23 ECDIS
with single click of button i want to update.
for that how can i do using csharp.
try this on your Update Button Click
int i = 0; int j = 0; con = new OleDbConnection("YourConnectionString");//Which ever connection you are using con.Open(); while (i < dataGridView1.Rows.Count) { string str = "update YourTableName set YourColumnName='" + dataGridView1.Rows[1].Cells[i].Value + "' where RommNo='" + dataGridView1.Rows[0].Cells[i].Value + "'";//you update query cmd = new OleDbCommand(str(), con); cmd.ExecuteNonQuery(); i += 1; } i = 0; while (i < DataGridView1.Rows.Count) { str() = "update YourTableName set YourColumnName='" + dataGridView1.Rows[3].Cells[i].Value + "' where RommNo='" + dataGridView1.Rows[2].Cells[i].Value + "'";//Your update query cmd = new OleDbCommand(str(), con); cmd.ExecuteNonQuery(); i += 1; }
Are you looking for something like this.
Bulk Edit Update Delete in Gridview[^]
Regards.. :laugh:
这篇关于如何使用单击按钮更新每个gridview行并在数据库中更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!