Jump to content

How to update a database successfully

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
2 replies to this topic

#1
mechslayer

mechslayer

    Learning Programmer

  • Members
  • PipPipPip
  • 45 posts
Hi everyone,

I encountered a problem when trying to do a simple programme of adding, editing of database using VB express edition 2008 with SQL Server 2005 Express Edition.

I was able to add in data but when I tried to edit the data its failed.

My programme will worked in this way:

To do a clock-in and clock-out system for users.

When the user entered their ID number,

if they haven clocked in yet, the programme will add new data for the user with when and where they clocked in data filled in for them.

if they clocked in before, the programme will edit the data by changing the clock out data from "" to current time.

I add data by:

Me.CarLocationBindingSource.AddNew()
UserIDTextBox.Text = UserID
ClockINTextBox.Text = TimeOfDay
LocationTextBox.Text = Locations
Try
Me.Validate()
Me.CarLocationBindingSource.EndEdit()
Me.TableAdapterManager.UpdateAll(Me.CarLocationDataSet)
Catch ex As Exception
MsgBox("Update failed")
End Try

Edit data:

Dim TheCarLocationRow As CarLocationDataSet.CarLocationRow
TheCarLocationRow = CarLocationDataSet.CarLocation.FindByUserID(Form1TextboxOfDataChecking.Text)
TheCarLocationRow.ClockOUT = TimeOfDay
CarLocationDataSet.CarLocation.AcceptChanges()
Try
Me.Validate()
Me.CarLocationBindingSource.EndEdit()
Me.TableAdapterManager1.UpdateAll(CarLocationDataSet)
MsgBox("Update successful")
Catch ex As Exception
MsgBox("Update failed")
End Try

I can add in new data but can't update the data.

I just figured all this commands by seeing the help section. But I guess I need more than just some simple commands to save the data I edited.

Thanks in advance.. :)

#2
Orjan

Orjan

    Writes binary right handed and hex left handed

  • Moderators
  • 3,298 posts
Hmm, where do you write and update the database?

is it the TableAdapterManager that manage that?

#3
mechslayer

mechslayer

    Learning Programmer

  • Members
  • PipPipPip
  • 45 posts
Yes... I just think I lacked something but I don't know what is it.