Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

simple visual studio question - updating record 1

Status
Not open for further replies.

ajking

Technical User
Aug 13, 2002
229
I have recently migrated from VB programming behind MSAccess and am following lesson09 in the visual basic 2005 express edition regarding updating Database records using a very simple example but, no matter what I try, the source table is not updating. One would presume the instructional video and code would give the desired result but I cannot get the database record to update even though I have used the lesson09 coding included here:

Public Class Form2

Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Me.CustomerTableAdapter1.Fill(Me.MyCompanyDataSet1.Customer)
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

BindingSource1.EndEdit()
CustomerTableAdapter1.Update(MyCompanyDataSet1.Customer)

End Sub
End Class

Any suggestions would be much appreciated as I don't want to proceed further until I have got my head around this. TIA


'Life is what happens to you while you are busy making other plans' John W. Lennon 1940-1980
 
Hi again Aj!

ok have you set the UpdateCommand properties for the DataAdapter? You can manually write the SQL and populate the UpdateCommand, InsertCommand and DeleteCommand properties (you can also have VS do it for you)


Cheers

Nick
 
Hi Nick
Thanks for comimg back so quickly.
Can you elaborate on this as I followed the steps laid down in the tutorial which doesn't appear to mention this.

regards
Alan

'Life is what happens to you while you are busy making other plans' John W. Lennon 1940-1980
 
Alan, ok, I'm running blind here as I dont have VS on PC I'm on just now and I can't remember how you go about doing this automagically in VS but I think you can just double click on the adapter and it gives you these options.

To do it in code you can do something like this:

Code:
CustomerTableAdapter1.UpdateCommand = New SqlCommand("Update MyTable Set MyValues = NewValues", connectionstring)

CustomerTableAdapter1.Update(MyCompanyDataSet1.Customer)

or you can use the command automatically generated by the CommandBuilder

Code:
Dim cmdBuilder As SqlCommandBuilder = _
               New SqlCommandBuilder(adaptor)

CustomerTableAdapter1.UpdateCommand = cmdBuilder.GetUpdateCommand()

It goes something like that! (sorry it's hard when cant test!)

Also have a look here for details on the SQLCommandBuilder


Nick
 
Nick
thanks for all your help in this. I am sure it will point me in the right direction.
Mind you, you would have thought that MSDN would have used an example that 'does exactly what it says on the tin" ;-)

'Life is what happens to you while you are busy making other plans' John W. Lennon 1940-1980
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top