Hello,
i want to auto update a datatable (SQLDataAdapter.Update(myDatatable)
) during RowChanged event

It is possible?

thanks
wgn

Re: Auto update data on RowChanged by Cor

Cor
Tue Aug 30 09:57:51 CDT 2005

Wigno,

> i want to auto update a datatable (SQLDataAdapter.Update(myDatatable)
> ) during RowChanged event
>
> It is possible?
>
Why would it not be possible?

Cor



Re: Auto update data on RowChanged by Wigno

Wigno
Tue Aug 30 10:36:22 CDT 2005

On Tue, 30 Aug 2005 16:57:51 +0200, Cor Ligthert [MVP] wrote:

> Wigno,
>
>> i want to auto update a datatable (SQLDataAdapter.Update(myDatatable)
>> ) during RowChanged event
>>
>> It is possible?
>>
> Why would it not be possible?
>
> Cor
I have this problem:

1) i have a datagrid binded to a dataview of a datatable(myDataTable)
2) when add/change/delete a row i want update the db
with mySQLDataAdapter.Update(myDataTable)


If i put mySQLDataAdapter.Update(myDataTable) in a myDataTable_RowChanged
event i have strange behavior

How i can implement a solution to my problem?

thanks

wgn

Re: Auto update data on RowChanged by Cor

Cor
Tue Aug 30 11:19:17 CDT 2005

Wigno,

> If i put mySQLDataAdapter.Update(myDataTable) in a myDataTable_RowChanged
> event i have strange behavior
>
What do you call a strange behavior?

Comes there smoke out of the computer?

Cor



Re: Auto update data on RowChanged by Wigno

Wigno
Tue Aug 30 11:33:38 CDT 2005

On Tue, 30 Aug 2005 18:19:17 +0200, Cor Ligthert [MVP] wrote:

> Wigno,
>
>> If i put mySQLDataAdapter.Update(myDataTable) in a myDataTable_RowChanged
>> event i have strange behavior
>>
> What do you call a strange behavior?
>
> Comes there smoke out of the computer?
>
> Cor

When i call mySqlDataAdapter.Update(myDataTable) in
myDataTable_RowChanged the datatable fires another RowChanged event and
another's one until the exception a datareader is already open .....




Re: Auto update data on RowChanged by Marina

Marina
Tue Aug 30 13:38:23 CDT 2005

It is probably because calling Update, commits the data to the rows by
calling AcceptChanges. Which in turn fires the RowChanged event.

Check the Action property of the arguments, and only do the Update at the
right time.

"Wigno" <Wigno@libero.it> wrote in message
news:pan.2005.08.30.16.33.37.858848@libero.it...
> On Tue, 30 Aug 2005 18:19:17 +0200, Cor Ligthert [MVP] wrote:
>
>> Wigno,
>>
>>> If i put mySQLDataAdapter.Update(myDataTable) in a
>>> myDataTable_RowChanged
>>> event i have strange behavior
>>>
>> What do you call a strange behavior?
>>
>> Comes there smoke out of the computer?
>>
>> Cor
>
> When i call mySqlDataAdapter.Update(myDataTable) in
> myDataTable_RowChanged the datatable fires another RowChanged event and
> another's one until the exception a datareader is already open .....
>
>
>



Re: Auto update data on RowChanged by Cor

Cor
Tue Aug 30 13:56:35 CDT 2005

Marina and Wigno

> It is probably because calling Update, commits the data to the rows by
> calling AcceptChanges. Which in turn fires the RowChanged event.
>
> Check the Action property of the arguments, and only do the Update at the
> right time.
>
This can than in my opinion only once. If all datrow.states are set to not
changed than there is nothing to be updated.

However it can maybe tried with this

\\\
if ds.haschanges then
da.update(ds.getchanges)
ds.acceptchanges
end if
///


Cor



Re: Auto update data on RowChanged by Wigno

Wigno
Tue Aug 30 13:49:30 CDT 2005

On Tue, 30 Aug 2005 14:38:23 -0400, Marina wrote:

> It is probably because calling Update, commits the data to the rows by
> calling AcceptChanges. Which in turn fires the RowChanged event.
>
> Check the Action property of the arguments, and only do the Update at the
> right time.
>
> "Wigno" <Wigno@libero.it> wrote in message
> news:pan.2005.08.30.16.33.37.858848@libero.it...
>> On Tue, 30 Aug 2005 18:19:17 +0200, Cor Ligthert [MVP] wrote:
>>
>>> Wigno,
>>>
>>>> If i put mySQLDataAdapter.Update(myDataTable) in a
>>>> myDataTable_RowChanged
>>>> event i have strange behavior
>>>>
>>> What do you call a strange behavior?
>>>
>>> Comes there smoke out of the computer?
>>>
>>> Cor
>>
>> When i call mySqlDataAdapter.Update(myDataTable) in
>> myDataTable_RowChanged the datatable fires another RowChanged event and
>> another's one until the exception a datareader is already open .....
>>
>>
>>


What is the right time?







Re: Auto update data on RowChanged by Wigno

Wigno
Tue Aug 30 14:18:55 CDT 2005

On Tue, 30 Aug 2005 20:56:35 +0200, Cor Ligthert [MVP] wrote:

> Marina and Wigno
>
>> It is probably because calling Update, commits the data to the rows by
>> calling AcceptChanges. Which in turn fires the RowChanged event.
>>
>> Check the Action property of the arguments, and only do the Update at the
>> right time.
>>
> This can than in my opinion only once. If all datrow.states are set to not
> changed than there is nothing to be updated.
>
> However it can maybe tried with this
>
> \\\
> if ds.haschanges then
> da.update(ds.getchanges)
> ds.acceptchanges
> end if
> ///
>
>
> Cor

If you execute ds.acceptchanges the last row disappear



Re: Auto update data on RowChanged by Marina

Marina
Tue Aug 30 14:32:09 CDT 2005

I am guessing when the Action is Changed, but not the other ones.

You will have to experiment.

"Wigno" <Wigno@libero.it> wrote in message
news:pan.2005.08.30.18.49.28.773952@libero.it...
> On Tue, 30 Aug 2005 14:38:23 -0400, Marina wrote:
>
>> It is probably because calling Update, commits the data to the rows by
>> calling AcceptChanges. Which in turn fires the RowChanged event.
>>
>> Check the Action property of the arguments, and only do the Update at the
>> right time.
>>
>> "Wigno" <Wigno@libero.it> wrote in message
>> news:pan.2005.08.30.16.33.37.858848@libero.it...
>>> On Tue, 30 Aug 2005 18:19:17 +0200, Cor Ligthert [MVP] wrote:
>>>
>>>> Wigno,
>>>>
>>>>> If i put mySQLDataAdapter.Update(myDataTable) in a
>>>>> myDataTable_RowChanged
>>>>> event i have strange behavior
>>>>>
>>>> What do you call a strange behavior?
>>>>
>>>> Comes there smoke out of the computer?
>>>>
>>>> Cor
>>>
>>> When i call mySqlDataAdapter.Update(myDataTable) in
>>> myDataTable_RowChanged the datatable fires another RowChanged event and
>>> another's one until the exception a datareader is already open .....
>>>
>>>
>>>
>
>
> What is the right time?
>
>
>
>
>
>



Re: Auto update data on RowChanged by Cor

Cor
Wed Aug 31 03:14:32 CDT 2005

Wigno,

I tested it with this and had no problems.
(I had problems with that haschanges however that is not your problem and I
did not look further to it).

I think that the trick is that adding from the handler after that the
datasource is set.

\\\
Private da As SqlDataAdapter
Private ds As New DataSet
Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim conn As New SqlConnection("Server=Kamer;" & _
"DataBase=Northwind; Integrated Security=SSPI")
Dim sqlstr As String = "SELECT * FROM Employees"
da = New SqlDataAdapter(sqlstr, conn)
da.Fill(ds)
DataGrid1.DataSource = ds.Tables(0)
AddHandler ds.Tables(0).RowChanged, AddressOf dt_RowChanged
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
If ds.Tables(0).Rows(2)("FirstName").ToString = "Janet" Then
ds.Tables(0).Rows(2)("FirstName") = "Marie"
Else
ds.Tables(0).Rows(2)("FirstName") = "Janet"
End If
End Sub
Private Sub dt_RowChanged(ByVal sender As Object, _
ByVal e As System.Data.DataRowChangeEventArgs)
Dim cmb As New SqlCommandBuilder(da)
da.Update(ds)
End Sub
///

I hope this helps,

Cor



Re: Auto update data on RowChanged by wigno

wigno
Wed Aug 31 05:42:39 CDT 2005

Thank you very much for all your support.

Now,
my datagrid is binded to a dataview.
I have solved my problem using updating the database in the event
ListChanged of my dataview.

Deleted rows creates problem in this event so i put the code
to delete the row in the event CurrentCellChanged of my datagrid.

Now all works fine... i have a connected datagrid

thanks


Dim merging As Boolean = False
Private Sub dvDocArticoli_ListChanged(ByVal sender As Object, ByVal e
As System.ComponentModel.ListChangedEventArgs) Handles
dvDocArticoli.ListChanged
If (dsDati.HasChanges(DataRowState.Added)) And Not merging Then
merging = True
daDocArticoli.Update(dsDati.DOCUMENTI_ARTICOLI)
dsDati.AcceptChanges()
merging = False
End If
If dsDati.HasChanges(DataRowState.Deleted) And Not merging Then
Exit Sub
End If
If dsDati.HasChanges() And Not merging Then
merging = True
daDocArticoli.Update(dsDati.DOCUMENTI_ARTICOLI.GetChanges())
dsDati.AcceptChanges()
merging = False
End If
End Sub


On Wed, 31 Aug 2005 10:14:32 +0200, Cor Ligthert [MVP]
<notmyfirstname@planet.nl> wrote:


> Wigno,
>
> I tested it with this and had no problems.
> (I had problems with that haschanges however that is not your problem
> and I
> did not look further to it).
>
> I think that the trick is that adding from the handler after that the
> datasource is set.
>
> \\\
> Private da As SqlDataAdapter
> Private ds As New DataSet
> Private Sub Form1_Load(ByVal sender As System.Object, _
> ByVal e As System.EventArgs) Handles MyBase.Load
> Dim conn As New SqlConnection("Server=Kamer;" & _
> "DataBase=Northwind; Integrated Security=SSPI")
> Dim sqlstr As String = "SELECT * FROM Employees"
> da = New SqlDataAdapter(sqlstr, conn)
> da.Fill(ds)
> DataGrid1.DataSource = ds.Tables(0)
> AddHandler ds.Tables(0).RowChanged, AddressOf dt_RowChanged
> End Sub
> Private Sub Button1_Click(ByVal sender As System.Object, _
> ByVal e As System.EventArgs) Handles Button1.Click
> If ds.Tables(0).Rows(2)("FirstName").ToString = "Janet" Then
> ds.Tables(0).Rows(2)("FirstName") = "Marie"
> Else
> ds.Tables(0).Rows(2)("FirstName") = "Janet"
> End If
> End Sub
> Private Sub dt_RowChanged(ByVal sender As Object, _
> ByVal e As System.Data.DataRowChangeEventArgs)
> Dim cmb As New SqlCommandBuilder(da)
> da.Update(ds)
> End Sub
> ///
>
> I hope this helps,
>
> Cor
>
>



--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/