本文介绍了保存在DataGridView中所做的更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我一直在寻找在 DataGridView中保存数据更改的示例。有各种各样的例子,但没有一个真正显示如何保存更改 。有人请帮助我。 我有一个Windows Forms程序,其中DataGridView和BindingSource 添加到表单中。这是我用来填充网格的代码: Dim CRClassesTableAdapter As SqlDataAdapter Dim CRClassesTable As New DataTable() Dim connectionString As New SqlConnection(" Initial Catalog ="& My.Settings.Database&" ;; Data Source ="& My.Settings.Server& " ;; Integrated Security = SSPI;") CRClassesTableAdapter = New SqlDataAdapter(" Select * from CRClasses", connectionString) CRClassesTableAdapter.Fill(CRClassesTable) BindingSource1.DataSource = CRClassesTable BindingSource1.Filter =" fldCLStatus<''已关闭''和fldStartDate> = ''" &安培; medStart.Text& "''和fldStartDate< =''" &安培; medEnd.Text& "''" BindingSource1.Sort =" fldStartDate,fldClassName" Grid1.DataSource = BindingSource1 Databse在SQL Server 2000中。我正在使用VB2005。我希望每一行 在该行失去焦点后更新。我该怎么做? 解决方案 查看DataAdaptor的UpdateCommand。 B. 查看DataAdaptor的UpdateCommand。 B. 这就是我尝试过的,但我只是得到错误。我正在尝试这样做:这个: Me.Validate() Me.BindingSource1.EndEdit() CRClassesTableAdapter.Update(CRClassesTable) 我收到错误:更新时传递时需要有效的UpdateCommand DataRow集合修改过的行。 我正在寻找的是一个代码示例。 查看DataAdaptor的UpdateCommand。 B. 这就是我尝试过的,但我只是得到错误。我正在尝试这样做:这个: Me.Validate() Me.BindingSource1.EndEdit() CRClassesTableAdapter.Update(CRClassesTable) 我收到错误:更新时传递时需要有效的UpdateCommand DataRow集合修改过的行。 我正在寻找的是一个代码示例。 I''ve been searching forever for examples of saving data changes in aDataGridView. There''s all kinds of examples, but none really show howto save changes. Someone please help me.I have a Windows Forms program with a DataGridView and a BindingSourceadded to a form. Here is the code I''m using to populate the grid:Dim CRClassesTableAdapter As SqlDataAdapterDim CRClassesTable As New DataTable()Dim connectionString As New SqlConnection("Initial Catalog=" &My.Settings.Database & ";Data Source=" & My.Settings.Server &";Integrated Security=SSPI;")CRClassesTableAdapter = New SqlDataAdapter("Select * from CRClasses",connectionString)CRClassesTableAdapter.Fill(CRClassesTable)BindingSource1.DataSource = CRClassesTableBindingSource1.Filter = "fldCLStatus <''Closed'' AND fldStartDate >=''" & medStart.Text & "'' AND fldStartDate <= ''" & medEnd.Text & "''"BindingSource1.Sort = "fldStartDate, fldClassName"Grid1.DataSource = BindingSource1Databse is in SQL Server 2000. I''m using VB2005. I would like each rowto update once that row has lost focus. How would I do it? 解决方案Look at the DataAdaptor''s UpdateCommand.B. Look at the DataAdaptor''s UpdateCommand.B.That''s what I''ve tried doing, but I just get errors. I''m trying to dothis:Me.Validate()Me.BindingSource1.EndEdit()CRClassesTableAdapter.Update(CRClassesTable)I get the error: "Update requires a valid UpdateCommand when passedDataRow collection with modified rows."What I''m looking for is a CODE EXAMPLE. Look at the DataAdaptor''s UpdateCommand.B.That''s what I''ve tried doing, but I just get errors. I''m trying to dothis:Me.Validate()Me.BindingSource1.EndEdit()CRClassesTableAdapter.Update(CRClassesTable)I get the error: "Update requires a valid UpdateCommand when passedDataRow collection with modified rows."What I''m looking for is a CODE EXAMPLE. 这篇关于保存在DataGridView中所做的更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 06-21 10:42