Home All Groups Group Topic Archive Search About

Why won't my DataTable.Update?

Author
6 Jan 2006 1:02 AM
Mike
Dear Group,

I have a .NET 2.0 .DLL assembly containing a dataset with three tables. I
reference this from a standalone .NET 2.0 EXE. I am writing a login form
which uses the single Dataset from the .NET 2.0 .DLL. One of the tables
(staff) contains a TableAdapter that fills using a single parameter
(@UserName). I am trying to code a simple login form for which I pass a
username and read the password. All is well and fine with this, however I
want to write back to the "lastlogon" column and update it with a timestamp.
I'm only using one table, so this shouldn't be too difficult?

The following code doesn't break at all, but the table never updates. What
am I doing wrong? I'm worried that I might be updating my own TableAdapter
in memory which is disconnected from the database, or my instance of my
TableAdapter isn't connected to the satellite .DLL assembly. The satellite
..DLL assembly is strongly named and the Dataset Strongly Typed. Any ideas?
Thanks in advance for any help!

Dim StaffDT As Staff.STAFFDataTable
Dim StaffTA As StaffTableAdapters.STAFFTableAdapter

StaffDT = New Staff.STAFFDataTable

StaffTA = New StaffTableAdapters.STAFFTableAdapter

StaffTA.FillByUserName(StaffDT, UsernameTextBox.Text)

' Found this username
If StaffDT.Rows.Count = 1 Then

' Check password
If StaffDT.Rows(0).Item("password") = Trim(PasswordTextBox.Text) Then

  ' Mark this login attempt
  StaffDT.Rows(0).Item("lastlogon") = Now()

  ' Accept Changes
  StaffDT.AcceptChanges()

  ' Commit Changes
  StaffTA.Update(StaffDT)

  ' Show Switchboard (successful login)
  ShowSwitchboard()

Else
  MsgBox("Incorrect Password", MsgBoxStyle.Exclamation,
My.Application.Info.AssemblyName)

End If

Else

MsgBox("This username cannot be found in the database. Please ask your
system administrator to create a username for you", _
  MsgBoxStyle.Exclamation, My.Application.Info.AssemblyName)

End If

Author
6 Jan 2006 1:18 AM
Mike
"Mike" <none> wrote in message
news:%2331AczlEGHA.2712@TK2MSFTNGP10.phx.gbl...
>  ' Accept Changes
>  StaffDT.AcceptChanges()

If I remove this line, everything works. Any idea why?

Also if anyone's reading this and knows how - where can I find the Data Form
Wizard? It's not available on my development environment.

Warm Regards,

Mike
Author
6 Jan 2006 9:10 AM
Cor Ligthert [MVP]
Mike,

>>  ' Accept Changes
>>  StaffDT.AcceptChanges()
>
> If I remove this line, everything works. Any idea why?

AcceptChanges is an abbreviation for

Accept changes in the dataset/datatable as if all updates are done.
(One of the most misleading methods names for newbies and than they forget
in never more).

To push the changes from a control to a datasource you have to use the
EndCurrentEdit

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemwindowsformsbindingmanagerbaseclassendcurrentedittopic.asp

I hope this helps,

Cor
Author
7 Jan 2006 3:48 AM
Mike
Show quote
"Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> wrote in message
news:uYtAEEqEGHA.1816@TK2MSFTNGP11.phx.gbl...
> Mike,
>
>>>  ' Accept Changes
>>>  StaffDT.AcceptChanges()
>>
>> If I remove this line, everything works. Any idea why?
>
> AcceptChanges is an abbreviation for
>
> Accept changes in the dataset/datatable as if all updates are done.
> (One of the most misleading methods names for newbies and than they forget
> in never more).

Oh yes, that was confusing! Thanks for the explanation.

I have a BindingNavigator rather than a BindingManager, yet when I call the
..EndEdit() method on another form, nothing happens - I've tried checking SQL
Profiler and no SQL statements go through to the database. Any ideas?

Warm Regards,

Mike
Author
7 Jan 2006 9:26 AM
Cor Ligthert [MVP]
Mike

The endedit does as far as I have seen nothing,

If this is a problem try than that endcurrenedit

In this sample you can see it used at the end

http://www.vb-tips.com/default.aspx?ID=0bcf3aa6-0da7-4a6e-9061-ac8b53818af6

I hope this helps,

Cor
Author
7 Jan 2006 1:05 PM
Mike
"Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> wrote in message
news:Olc4tx2EGHA.1424@TK2MSFTNGP12.phx.gbl...
> Mike
>
> The endedit does as far as I have seen nothing,
>
> If this is a problem try than that endcurrenedit
>
> In this sample you can see it used at the end
>
> http://www.vb-tips.com/default.aspx?ID=0bcf3aa6-0da7-4a6e-9061-ac8b53818af6
>
> I hope this helps,

I can't use EndCurrentEdit as it is not a method available in either the
DataSet, BindingSource or BindingNavigator objects.

> BindingContext(DirectCast(DataGridView1.DataSource,
> DataView)).EndCurrentEdit() <

Mike
Author
7 Jan 2006 1:43 PM
Cor Ligthert [MVP]
Show quote
"Mike" <none> schreef in bericht
news:%23E43Ss4EGHA.3000@TK2MSFTNGP14.phx.gbl...
> "Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> wrote in message
> news:Olc4tx2EGHA.1424@TK2MSFTNGP12.phx.gbl...
>> Mike
>>
>> The endedit does as far as I have seen nothing,
>>
>> If this is a problem try than that endcurrenedit
>>
>> In this sample you can see it used at the end
>>
>> http://www.vb-tips.com/default.aspx?ID=0bcf3aa6-0da7-4a6e-9061-ac8b53818af6
>>
>> I hope this helps,
>
> I can't use EndCurrentEdit as it is not a method available in either the
> DataSet, BindingSource or BindingNavigator objects.
>
Probably,

BindingContext(StaffDT).EndCurrentEdit()

Or show otherwise the code where you bind your data to the controls.

Cor
Author
7 Jan 2006 4:12 PM
Mike
"Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> wrote in message
news:uOaTOB5EGHA.1816@TK2MSFTNGP11.phx.gbl...

> BindingContext(StaffDT).EndCurrentEdit()

Does nothing.

> Or show otherwise the code where you bind your data to the controls.

There is no code. This form was created completely in the Windows Form
Designer.

Mike

AddThis Social Bookmark Button