保存在DataGridView中所做的更改 [英] Saving changes made in DataGridView

查看:56
本文介绍了保存在DataGridView中所做的更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在寻找在
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。我希望每一行

在该行失去焦点后更新。我该怎么做?

解决方案



Kevin写道:


我一直在寻找在
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",br />
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.


2006年8月25日08:11:22 -0700,Brian Tkatch

< Ma *********** @ ThePentagon。 comwrote:


>
Kevin写道:


>我去过永远搜索在DataGridView中保存数据更改的示例。有各种各样的例子,但没有一个真正显示如何保存更改。有人请帮助我。

我有一个Windows Forms程序,其中添加了一个DataGridView和一个BindingSource
。这是我用来填充网格的代码:

Dim CRClassesTableAdapter As SqlDataAdapter
Dim CRClassesTable As New DataTable()
Dim connectionString As New SqlConnection (初始目录="&
My.Settings.Database&" ;; Data Source =&& My.Settings.Server&
" ;; Integrated Security = SSPI; ")

CRClassesTableAdapter =新的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.



这就是我尝试过的,但我只是得到错误。我正在尝试这样做:
这个:


Me.Validate()

Me.BindingSource1.EndEdit()

CRClassesTableAdapter.Update(CRClassesTable)


我收到错误:更新时传递时需要有效的UpdateCommand

DataRow集合修改过的行。

我正在寻找的是一个代码示例。


Kevin,

因为你不使用设计师而不是自己建造设计师。通过

实例这个

http://www.vb-tips.com/dbPages.aspx?...2-d7c12bbb3726


但是如果您的选择很简单,您也可以使用命令构建器。

http://msdn.microsoft.com/library/de...classtopic.asp


我希望这会有所帮助,


Cor

" Kevin" < ke **** @ cfl.rr.comschreef在bericht

新闻:5k ************************ ******** @ 4ax.com ...


2006年8月25日08:11:22 -0700,Brian Tkatch

< Ma *********** @ ThePentagon.comwrote:


>>
Kevin写道:


>>我一直在寻找在DataGridView中保存数据更改的例子。有各种各样的例子,但没有一个真正显示如何保存更改。有人请帮助我。

我有一个Windows Forms程序,其中添加了一个DataGridView和一个BindingSource
。这是我用来填充网格的代码:

Dim CRClassesTableAdapter As SqlDataAdapter
Dim CRClassesTable As New DataTable()
Dim connectionString As New SqlConnection (初始目录="&
My.Settings.Database&" ;; Data Source =&& My.Settings.Server&
" ;; Integrated Security = SSPI; ")

CRClassesTableAdapter =新的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.




这就是我尝试过的,但我只是得到错误。我正在尝试这样做:
这个:


Me.Validate()

Me.BindingSource1.EndEdit()

CRClassesTableAdapter.Update(CRClassesTable)


我收到错误:更新时传递时需要有效的UpdateCommand

DataRow集合修改过的行。


我正在寻找的是一个代码示例。



I''ve been searching forever for examples of saving data changes in a
DataGridView. There''s all kinds of examples, but none really show how
to save changes. Someone please help me.

I have a Windows Forms program with a DataGridView and a BindingSource
added to a form. Here is the code I''m using to populate the grid:
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 <''Closed'' AND fldStartDate >=
''" & medStart.Text & "'' AND fldStartDate <= ''" & medEnd.Text & "''"

BindingSource1.Sort = "fldStartDate, fldClassName"

Grid1.DataSource = BindingSource1
Databse is in SQL Server 2000. I''m using VB2005. I would like each row
to update once that row has lost focus. How would I do it?

解决方案


Kevin wrote:

I''ve been searching forever for examples of saving data changes in a
DataGridView. There''s all kinds of examples, but none really show how
to save changes. Someone please help me.

I have a Windows Forms program with a DataGridView and a BindingSource
added to a form. Here is the code I''m using to populate the grid:
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 <''Closed'' AND fldStartDate >=
''" & medStart.Text & "'' AND fldStartDate <= ''" & medEnd.Text & "''"

BindingSource1.Sort = "fldStartDate, fldClassName"

Grid1.DataSource = BindingSource1
Databse is in SQL Server 2000. I''m using VB2005. I would like each row
to update once that row has lost focus. How would I do it?

Look at the DataAdaptor''s UpdateCommand.

B.


On 25 Aug 2006 08:11:22 -0700, "Brian Tkatch"
<Ma***********@ThePentagon.comwrote:

>
Kevin wrote:

>I''ve been searching forever for examples of saving data changes in a
DataGridView. There''s all kinds of examples, but none really show how
to save changes. Someone please help me.

I have a Windows Forms program with a DataGridView and a BindingSource
added to a form. Here is the code I''m using to populate the grid:
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 <''Closed'' AND fldStartDate >=
''" & medStart.Text & "'' AND fldStartDate <= ''" & medEnd.Text & "''"

BindingSource1.Sort = "fldStartDate, fldClassName"

Grid1.DataSource = BindingSource1
Databse is in SQL Server 2000. I''m using VB2005. I would like each row
to update once that row has lost focus. How would I do it?


Look at the DataAdaptor''s UpdateCommand.

B.


That''s what I''ve tried doing, but I just get errors. I''m trying to do
this:

Me.Validate()
Me.BindingSource1.EndEdit()
CRClassesTableAdapter.Update(CRClassesTable)

I get the error: "Update requires a valid UpdateCommand when passed
DataRow collection with modified rows."
What I''m looking for is a CODE EXAMPLE.


Kevin,
As you don''t use the designer than you have to build those yourself. By
instance this

http://www.vb-tips.com/dbPages.aspx?...2-d7c12bbb3726

However if your select is easy you can as well use the commandbuilder.

http://msdn.microsoft.com/library/de...classtopic.asp

I hope this helps,

Cor
"Kevin" <ke****@cfl.rr.comschreef in bericht
news:5k********************************@4ax.com...

On 25 Aug 2006 08:11:22 -0700, "Brian Tkatch"
<Ma***********@ThePentagon.comwrote:

>>
Kevin wrote:

>>I''ve been searching forever for examples of saving data changes in a
DataGridView. There''s all kinds of examples, but none really show how
to save changes. Someone please help me.

I have a Windows Forms program with a DataGridView and a BindingSource
added to a form. Here is the code I''m using to populate the grid:
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 <''Closed'' AND fldStartDate >=
''" & medStart.Text & "'' AND fldStartDate <= ''" & medEnd.Text & "''"

BindingSource1.Sort = "fldStartDate, fldClassName"

Grid1.DataSource = BindingSource1
Databse is in SQL Server 2000. I''m using VB2005. I would like each row
to update once that row has lost focus. How would I do it?


Look at the DataAdaptor''s UpdateCommand.

B.



That''s what I''ve tried doing, but I just get errors. I''m trying to do
this:

Me.Validate()
Me.BindingSource1.EndEdit()
CRClassesTableAdapter.Update(CRClassesTable)

I get the error: "Update requires a valid UpdateCommand when passed
DataRow collection with modified rows."
What I''m looking for is a CODE EXAMPLE.



这篇关于保存在DataGridView中所做的更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆