将Datagridview保存到数据库 [英] Save Datagridview to Database
本文介绍了将Datagridview保存到数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在winforms应用程序中有一个datagridview,其中装有数据库表.
然后,当我对datagridview进行更改时,我想将datagridview保存到我的数据库中.我正在使用sql数据库.
这是我的代码:
I have a datagridview filled with a table of my database in my winforms Application.
Then I want to save datagridview to my database when I make changes to datagridview. I''m using sql Database.
Here is my code:
DataTable allData = new DataTable();
SqlCommand cmd = new SqlCommand("Select * from contactTable", Connection);
cmd.CommandType = CommandType.StoredProcedure;
Connection.Open();
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
adapter.Fill(allData);
Connection.Close();
contactTableTableAdapter.Update(allData);
但是这段代码什么也没发生.
最后,我使用插入语句将dataGridView输入到数据库中.
But nothing happens with this code.
At last I used insert statrements to enter the dataGridView to my database.
推荐答案
也许您可以研究 RowEditEnded 事件.
希望它能对您有帮助.
May be you can investigate about RowEditEnded event.
Hope it helps.
您能解释一下,以及您想达到什么并粘贴整个网格设计和过程以及输出变量
Could u explain a little More and what u want to achive and paste u r whole grid design and u r procedure and the out put var
这篇关于将Datagridview保存到数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文