使用DataGridView更新数据库 [英] Update database with DataGridView
本文介绍了使用DataGridView更新数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我已经从T-SQL的三个表(具有特定列)中填充了datagridview控件.
用户将在Datagridview中进行更改,而我必须更新该列.
我正在尝试以下代码:
Hi All,
I have populated datagridview control from three tables (with specific columns) of T-SQL.
User will make changes in Datagridview and I have to update that columns.
I am trying the following code:
ds.Tables[0].AcceptChanges();
adp.Update(changes);
但这不起作用.
问候!
Aman
But it is not working.
Regards!
Aman
推荐答案
大家好,
感谢您的支持.我使用以下方法通过datagridview更新数据库:
Hi Guys,
Thanx for your supports. I have used the following way to update database with datagridview:
SqlDataAdapter adp = new SqlDataAdapter();
adp.UpdateCommand = con.CreateCommand();
adp.UpdateCommand.CommandText = "SQlQuery";
adp.UpdateCommand.CommandType = CommandType.Text;
adp.UpdateCommand.Parameters.Add("@a",SqlDbType.VarChar, 50).Value = DataGridView1.Rows[e.RowIndex].Cells[1].Value;
adp.UpdateCommand.Parameters.Add("@AdjAmt", SqlDbType.Float).Value = Convert.ToSingle(DataGridView1.Rows[e.RowIndex].Cells[5].Value);
adp.UpdateCommand.ExecuteNonQuery();
adp.Dispose();
问候!
Aman
Regards!
Aman
嗨Aman4.net,
此问题 [
Hi Aman4.net,
This Question[^] I guess could contains what you are searching for.
I hope this help,
:)
希望使用DataGridView更新数据库 [ ^ ]会给您一个想法.
Hope Update database with DataGridView[^]will give you an idea.
这篇关于使用DataGridView更新数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文