473,379 Members | 1,252 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

Updating DataAdapter in Subroutines

I have a form that takes one Contact record and edit's it. The routine used
is as follows:

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

Dim strSQL As String

strSQL = "Select * from Contact WHERE sysID = '" & g_sysID & "'"
objDS.Clear()
Dim selectCommand As New SqlClient.SqlCommand(strSQL)
DA.SelectCommand = selectCommand
DA.SelectCommand.Connection = CN

DA.Fill(objDS, "Contact")

Me.txtFirstName.DataBindings.Add("Text", objDS,
"Contact.first_name")
Me.txtLastName.DataBindings.Add("Text", objDS, "Contact.Last_name")
Me.txtAddress1.DataBindings.Add("Text", objDS, "Contact.con1_02_03")
Me.txtPhone.DataBindings.Add("Text", objDS, "Contact.Phone1")
Me.txtCity.DataBindings.Add("Text", objDS, "Contact.con1_02_05")
Me.txtState.DataBindings.Add("Text", objDS, "Contact.con1_02_06")
Me.txtZip.DataBindings.Add("Text", objDS, "Contact.con1_02_07")
Me.txtEMail.DataBindings.Add("Text", objDS, "Contact.con1_03_01")

End Sub

This works fine and the fields get populated. When I want to update the
record I hit the "Save" button and execute the following:

Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnSave.Click

Try
Dim rows As Integer
DA.ContinueUpdateOnError = True
rows = DA.Update(objDS, "Contact")
If rows > 0 Then
MsgBox("Data updated")
Else
MsgBox("Data Not Updated")
End If

Catch ex As Exception

MsgBox(ex.Message)

End Try

End Sub

I get the message saying that the data is not updated. Any help would be
appreciated.

Thanks,

Gary
Nov 20 '05 #1
16 1153
Hi Gary,

Mostly the error is this

DirectCast(BindingContext(objds.Tables(0)),
CurrencyManager).EndCurrentEdit()

Place this as first statement in your update routine, if this does not solve
the problem I will look further, so message it than?

Cor
Nov 20 '05 #2
Hi Gary,

Mostly the error is this

DirectCast(BindingContext(objds.Tables(0)),
CurrencyManager).EndCurrentEdit()

Place this as first statement in your update routine, if this does not solve
the problem I will look further, so message it than?

Cor
Nov 20 '05 #3
Cor,

I tried the statement and it doesn't work. The table didn't get updated and
no error was generated.

Thanks,

Gary

"Cor Ligthert" <no*@planet.nl> wrote in message
news:O4**************@TK2MSFTNGP12.phx.gbl...
Hi Gary,

Mostly the error is this

DirectCast(BindingContext(objds.Tables(0)),
CurrencyManager).EndCurrentEdit()

Place this as first statement in your update routine, if this does not solve the problem I will look further, so message it than?

Cor

Nov 20 '05 #4
Cor,

I tried the statement and it doesn't work. The table didn't get updated and
no error was generated.

Thanks,

Gary

"Cor Ligthert" <no*@planet.nl> wrote in message
news:O4**************@TK2MSFTNGP12.phx.gbl...
Hi Gary,

Mostly the error is this

DirectCast(BindingContext(objds.Tables(0)),
CurrencyManager).EndCurrentEdit()

Place this as first statement in your update routine, if this does not solve the problem I will look further, so message it than?

Cor

Nov 20 '05 #5
Hi Gary,

You probably have nowhere created an insert an update and a delete command.

You can do that in a simple situation simple by adding the code beneath that
in the load after creating the dataadapter

cmb = New Sqlclient.SqlCommandBuilder(DA)

or by building all commands by hand (I would only do that if I had
problems).

Cor

Nov 20 '05 #6
Hi Gary,

You probably have nowhere created an insert an update and a delete command.

You can do that in a simple situation simple by adding the code beneath that
in the load after creating the dataadapter

cmb = New Sqlclient.SqlCommandBuilder(DA)

or by building all commands by hand (I would only do that if I had
problems).

Cor

Nov 20 '05 #7
Hi Cor,

Thanks for the quick reply. I added a dataadapter by "drag and drop" and
then looked at the generated code. Do I need to put all that code in
because I am doing all the command by hand or can I somehow use the
generated dataadapter code that was generated? Do I need all the parameters
statements generated, the Insert, Update, Delete statements also?

Can you show me the commands that I need to update my database or should I
just copy and rename what was generated by VB?

There must be 10 or more parameter statements associated with the Insert and
Update commands. What do most people do when they are learning VB.NET at
the beginning? Do they use the "wizards" to create everything or do they
dig in and learn it the way I'm trying to? I thought it would be better if
I could create all code by hand but it is an incredible task. I've been
doing VB 6 for a few years, but VB.NET is light years ahead and the learning
curve is pretty steep. I have a couple of books but mostly they have the
very basic (no pun intended) examples, but I guess thats why the newsgroups
are so popular!

Thanks,

Gary

"Cor Ligthert" <no**********@planet.nl> wrote in message
news:u6*************@tk2msftngp13.phx.gbl...
Hi Gary,

You probably have nowhere created an insert an update and a delete command.
You can do that in a simple situation simple by adding the code beneath that in the load after creating the dataadapter

cmb = New Sqlclient.SqlCommandBuilder(DA)

or by building all commands by hand (I would only do that if I had
problems).

Cor

Nov 20 '05 #8
Hi Cor,

Thanks for the quick reply. I added a dataadapter by "drag and drop" and
then looked at the generated code. Do I need to put all that code in
because I am doing all the command by hand or can I somehow use the
generated dataadapter code that was generated? Do I need all the parameters
statements generated, the Insert, Update, Delete statements also?

Can you show me the commands that I need to update my database or should I
just copy and rename what was generated by VB?

There must be 10 or more parameter statements associated with the Insert and
Update commands. What do most people do when they are learning VB.NET at
the beginning? Do they use the "wizards" to create everything or do they
dig in and learn it the way I'm trying to? I thought it would be better if
I could create all code by hand but it is an incredible task. I've been
doing VB 6 for a few years, but VB.NET is light years ahead and the learning
curve is pretty steep. I have a couple of books but mostly they have the
very basic (no pun intended) examples, but I guess thats why the newsgroups
are so popular!

Thanks,

Gary

"Cor Ligthert" <no**********@planet.nl> wrote in message
news:u6*************@tk2msftngp13.phx.gbl...
Hi Gary,

You probably have nowhere created an insert an update and a delete command.
You can do that in a simple situation simple by adding the code beneath that in the load after creating the dataadapter

cmb = New Sqlclient.SqlCommandBuilder(DA)

or by building all commands by hand (I would only do that if I had
problems).

Cor

Nov 20 '05 #9
Hi Gary,

You only needs this

cmb = New Sqlclient.SqlCommandBuilder(DA)

on a proper place, that build it however it is buggy is said when you have
complex insert update and delete commands

Cor
Nov 20 '05 #10
Hi Gary,

You only needs this

cmb = New Sqlclient.SqlCommandBuilder(DA)

on a proper place, that build it however it is buggy is said when you have
complex insert update and delete commands

Cor
Nov 20 '05 #11
Hi Cor,

Can you elaborate a bit more for me please. Where do I put the line? Do I
need to define cmb? Is this a global assign?

Thanks,

Gary

"Cor Ligthert" <no**********@planet.nl> wrote in message
news:uO**************@TK2MSFTNGP12.phx.gbl...
Hi Gary,

You only needs this

cmb = New Sqlclient.SqlCommandBuilder(DA)

on a proper place, that build it however it is buggy is said when you have
complex insert update and delete commands

Cor

Nov 20 '05 #12
Hi Cor,

Can you elaborate a bit more for me please. Where do I put the line? Do I
need to define cmb? Is this a global assign?

Thanks,

Gary

"Cor Ligthert" <no**********@planet.nl> wrote in message
news:uO**************@TK2MSFTNGP12.phx.gbl...
Hi Gary,

You only needs this

cmb = New Sqlclient.SqlCommandBuilder(DA)

on a proper place, that build it however it is buggy is said when you have
complex insert update and delete commands

Cor

Nov 20 '05 #13
Hi Gary

I am making a mash with you all errors comes with you

dim cmb as New Sqlclient.SqlCommandBuilder(DA)

I did want to stop however I was looking if it was working with you, message
me when it works or not your problem is so simple for me.

Sorry

Cor
Nov 20 '05 #14
Hi Gary

I am making a mash with you all errors comes with you

dim cmb as New Sqlclient.SqlCommandBuilder(DA)

I did want to stop however I was looking if it was working with you, message
me when it works or not your problem is so simple for me.

Sorry

Cor
Nov 20 '05 #15
Hi Gary,

I forgot place it direct before the update than we are sure it works.

Cor
Nov 20 '05 #16
Hi Gary,

I forgot place it direct before the update than we are sure it works.

Cor
Nov 20 '05 #17

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Tc | last post by:
Hi, I was curious, I am thinking of writing an application that loads a dataset from a database that resides on a server. The question I have is this, if multiple copies of the app will be...
16
by: Gary | last post by:
I have a form that takes one Contact record and edit's it. The routine used is as follows: Private Sub ContactMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles...
4
by: Dave Taylor | last post by:
I've been using the dataset designer in Visual Studio to create typed datasets for my application by dragging over tables from the Server Explorer and dropping them into the designer. The problem...
13
by: Doug Bell | last post by:
Hi, I thought I had this sorted this morning but it is still a problem. My application has a DataAccess Class. When it starts, it: Connects to a DB (OLE DB) If it connects it uses an...
2
by: Jason Huang | last post by:
Hi, I am wondering why use the DataTableMapping in SqlDataAdapter when Updating data. Would someone give me some advice? Thanks for help. Jason
4
by: Geoff | last post by:
Hi I'm hoping somebody can help me with the following problem that has occurred to me. Suppose I have two tables in an SQL Server database. Let's call these tables A and B. Assume that A has...
3
by: RSH | last post by:
Hi, I have a situation in where i have two instances of SQL server, the first is our Production Environment, the second is our Development environment. Both servers contain the same databases...
2
by: susan.f.barrett | last post by:
Hi, Despite me being able to type the following in to SQL Server and it updating 1 row: > updatestockcategory 1093, 839 In my code, it is not updating any rows. dataSet = new DataSet();
6
by: Rich | last post by:
Dim da As New SqlDataAdapter("Select * from tbl1", conn) dim tblx As New DataTable da.Fill(tblx) '--works OK up to this point da.UpdateCommand = New SqlCommand da.UpdateCommand.Connection =...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.