Updating Data

G

Gary

I have the following code to populate some textboxes on a form. This query
only brings in one record.

strSQL = "Select * from Contact WHERE sysID = '" & g_sysID & "'"

Dim DA As New SqlClient.SqlDataAdapter(strSQL, CN)

DA.Fill(objDS, "Contact")

Me.txtFirstName.DataBindings.Add("Text", objDS, "Contact.first_name")

Me.txtLastName.DataBindings.Add("Text", objDS, "Contact.Last_name")

Me.txtPhone.DataBindings.Add("Text", objDS, "Contact.Phone1")



and I want to update the fields when I am finished. What is the best way to
update? I tried a Bindingtext(objDS,"Contact").EndCurrentEdit and this
didn't work.

What is the bet way to update when I only have one row in the dataset? Any
help would be appreciated.



Thanks,

Gary
 
C

Cor

Hi Gary,

I see nothing wrong on first sight.

However when you want to update it than you need to do a dataadapter update
after that end current edit you are using. Put before that a commandbuilder.
When this is to few information message again.

And as advice remove that terrible obj before your ds, everything is an
object or a value in VB.net.

Cor
 
G

Gary

Cor,

Could you elaborate on exactly what commands I need? I don't understand. Be
verbose as I am new at VB.NET.

Thanks,

Gary
 
C

Cor Ligthert

Hi Gary,

strSQL = "Select * from Contact WHERE sysID = '" & g_sysID & "'"
Dim DA As New SqlClient.SqlDataAdapter(strSQL, CN)
DA.Fill(objDS, "Contact")
Me.txtFirstName.DataBindings.Add("Text", objDS, "Contact.first_name")
Me.txtLastName.DataBindings.Add("Text", objDS, "Contact.Last_name")
Me.txtPhone.DataBindings.Add("Text", objDS, "Contact.Phone1")

In a buttonclickevent (you make that by clicking on a button in the designer
than it apears in the bottom of your code)

I typed all here in confirming your code (wath typos), the error trapping is
very basic and should be in a multiuser environment more complete.

strSQL = "Select * from Contact WHERE sysID = '" & g_sysID & "'"
Dim DA As New SqlClient.SqlDataAdapter(strSQL, CN)
dim cmb as new SqlClient.SqlCommandbuilder(DA)
if objDs.haschanges then
Try
da.update(objDs)
Catch sqlExc As SqlException
MessageBox.Show(sqlExc.ToString)
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
end if

I hope this helps?

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top