473,569 Members | 2,648 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem with SQLDataAdapter and Update

Ok...I'm new to .NET. I have been programming in C,and VB since 1983.
I am trying to get a simple ADO.NET and Vb.NET example to run using
SQL Server and Northwind database.

I have a form with fields for Employee ID, Last Name, First Name, TitleOfCourtesy ,
and BirthDate. I have bound these to a dataset and DataAdapter.

'Create the SQL Connection, DataAdapter, and DataSet
mySQLConnection = New SqlConnection(" server=myServer ;database=North wind;Uid=me;Pwd =password;")
mySLQDataAdapte r = New SqlDataAdapter( "select * from Employees where EmployeeID=1", mySQLConnection )
mySLQDataAdapte r.TableMappings .Add("Employees ", "Employees" )
myDataSet = New DataSet

sqlCBuilder = New SqlCommandBuild er(mySLQDataAda pter)
mySLQDataAdapte r.DeleteCommand = sqlCBuilder.Get DeleteCommand()
mySLQDataAdapte r.InsertCommand = sqlCBuilder.Get InsertCommand()
mySLQDataAdapte r.UpdateCommand = sqlCBuilder.Get UpdateCommand()

mySLQDataAdapte r.MissingSchema Action = MissingSchemaAc tion.AddWithKey

mySLQDataAdapte r.Fill(myDataSe t, "Employees" )

'Bind Data to Controls
txtEmployeeID.D ataBindings.Add (New Binding("Text", myDataSet, "Employees.Empl oyeeID"))
txtLastName.Dat aBindings.Add(N ew Binding("Text", myDataSet, "Employees.Last Name"))
txtFirstName.Da taBindings.Add( New Binding("Text", myDataSet, "Employees.Firs tName"))
dtDOB.DataBindi ngs.Add(New Binding("Value" , myDataSet, "Employees.Birt hDate"))
txtTitle.DataBi ndings.Add(New Binding("Text", myDataSet, "Employees.Titl eOfCourtesy"))

This does everything it should, I believe. My fields are filled with the
correct record. The problem comes when I try to update the data. I make changes
to the LastName field and press my Save button. The button executes the following
code:

mySLQDataAdapte r.Update(myData Set, "Employees" )

No exceptions are thrown. However, the data is never updated. I checked the value
of the dataset field in the intermediate window
?me.myDataSet.T ables("Employee s").Rows(0).Ite m("LastName")
"Davolios" {String}
String: "Davolios"

(I added an s to the last name.)

I know I am overlooking something obvious, but I have looked at it toooooooo long.

Please help!
Thanks
Ranny

User submitted from AEWNET (http://www.aewnet.com/)
Nov 21 '05 #1
3 1347
Ranny,
\\\
Bindingcontext( myDataset.table s("Employees"). Endcurrentedit
///
before
mySLQDataAdapte r.Update(myData Set, "Employees" )

I hope this helps,

Cor
Nov 21 '05 #2
Cor
Thanks for the response. I guess I am kinda of slow. When I add that line
just in front of the update statement I get "'EndcurrentEdi t' is not a member of
'System.Data.Da taTable'".
What am I missing??????
Ranny
Ok...I'm new to .NET. I have been programming in C,and VB since 1983.
I am trying to get a simple ADO.NET and Vb.NET example to run using
SQL Server and Northwind database.

I have a form with fields for Employee ID, Last Name, First Name, TitleOfCourtesy ,
and BirthDate. I have bound these to a dataset and DataAdapter.

'Create the SQL Connection, DataAdapter, and DataSet
mySQLConnection = New SqlConnection(" server=myServer ;database=North wind;Uid=me;Pwd =password;")
mySLQDataAdapte r = New SqlDataAdapter( "select * from Employees where EmployeeID=1", mySQLConnection )
mySLQDataAdapte r.TableMappings .Add("Employees ", "Employees" )
myDataSet = New DataSet

sqlCBuilder = New SqlCommandBuild er(mySLQDataAda pter)
mySLQDataAdapte r.DeleteCommand = sqlCBuilder.Get DeleteCommand()
mySLQDataAdapte r.InsertCommand = sqlCBuilder.Get InsertCommand()
mySLQDataAdapte r.UpdateCommand = sqlCBuilder.Get UpdateCommand()

mySLQDataAdapte r.MissingSchema Action = MissingSchemaAc tion.AddWithKey

mySLQDataAdapte r.Fill(myDataSe t, "Employees" )

'Bind Data to Controls
txtEmployeeID.D ataBindings.Add (New Binding("Text", myDataSet, "Employees.Empl oyeeID"))
txtLastName.Dat aBindings.Add(N ew Binding("Text", myDataSet, "Employees.Last Name"))
txtFirstName.Da taBindings.Add( New Binding("Text", myDataSet, "Employees.Firs tName"))
dtDOB.DataBindi ngs.Add(New Binding("Value" , myDataSet, "Employees.Birt hDate"))
txtTitle.DataBi ndings.Add(New Binding("Text", myDataSet, "Employees.Titl eOfCourtesy"))

This does everything it should, I believe. My fields are filled with the
correct record. The problem comes when I try to update the data. I make changes
to the LastName field and press my Save button. The button executes the following
code:

mySLQDataAdapte r.Update(myData Set, "Employees" )

No exceptions are thrown. However, the data is never updated. I checked the value
of the dataset field in the intermediate window
?me.myDataSet.T ables("Employee s").Rows(0).Ite m("LastName")
"Davolios" {String}
String: "Davolios"

(I added an s to the last name.)

I know I am overlooking something obvious, but I have looked at it toooooooo long.

Please help!
Thanks
Ranny

User submitted from AEWNET (http://www.aewnet.com/)


User submitted from AEWNET (http://www.aewnet.com/)
Nov 21 '05 #3
Doh

\\\
Bindingcontext( myDataset.table s("Employees"). Endcurrentedit
///


Bindingcontext( myDataset.table s("Employees")) .Endcurrentedit
Nov 21 '05 #4

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

Similar topics

1
2099
by: Steven Blair | last post by:
Hi, Here is a short decsription of my problem. I have written a dll for Database accessing. I have one method which can return a Dataset and another method which takes a Dataset and upates a Database. (Disconnected Datasets). The problem I have is a new SqlAdapter is required before updating the Database: Therefore, to allow the update...
4
1871
by: Mullin Yu | last post by:
i have a stored procedure at sql server 2k. which will update records and select result from temp table. if i use SqlConnection class, and i do both. but, if i use OleDbConnection class, i can have only records updated, but no result come out. how can i debug, and what's the error? thanks!
3
1988
by: Steven Blair | last post by:
Hi, I have a problem understanding the SqlDataAdaptor and the DataSet. I have a dll which has various methods for running stored procedures etc. It also has a method which allows the client to return a DataSet from a table. The client can modify this DataSet and I have wrote a function which will take this DataSet back in and update the...
3
2339
by: W Akthar | last post by:
Hi I am trying to create a windows service which queries SQL Server on timed intervals and depending on the results send appointments to Outlook. The problem lies when I try to create an outlook application object.
7
1851
by: Zachary Hilbun | last post by:
The below is some test code to help me learn how to update a dataset. It is supposed to read the value of UserCounter and write it back. The UserCounter is being read correctly as 0, is 1 when written back, but is not being written back to the database. Although I've used a foreach loop there is actually only 1 record in the dataset. ...
3
2258
by: LP | last post by:
Hello, In the past I used SqlCommandBuilder and SqlDataAdapter .Update method to apply changes in a DataTable back to its table source in SQL Server. It worked fine when DataSet had only 1 table, this time I have 2 tables in a dataset and I want to update them all at once. However it only updates the first one and fails when attempts to...
2
1455
by: chris | last post by:
hi, i managed to populate my datagris and add a template colum to update the database. when i click the update button i get an error. is there something wrong with my code. ------------------code that populate the grid ar load Dim conPos As SqlConnection Dim cmdSel As SqlDataAdapter Dim ds As DataSet
4
2256
by: steroche | last post by:
I would REALLY appreciate help please please please! Im sure it is probably blindingly obvious to most of you but I am totally in the dark here!I am lost - i thought i had finally figured out this dataSet updating lark when i realised that i think i am right back at square 1!!! Here's my scenario - i have a SQLDB and i retrieve all my data...
9
2711
by: rn5a | last post by:
A Form has a DataGrid which displays records from a SQL Server 2005 DB table. Users can modify the records using this DataGrid for which I am using EditCommandColumn in the DataGrid. This is the code: <script runat="server"> Dim sqlConn As New SqlConnection(".....") Sub Page_Load(ByVal obj As Object, ByVal ea As EventArgs) If Not...
12
4126
by: Simon | last post by:
Hi all, I'm having a baffling problem with a windows service that I'm working on. Basically, I am using a typed dataset to insert a large number of rows into an SQL Server 2005 database. But there's a memory leak that seems to be to do with calling the data adapters update method. It's making the memory usage go through the roof and...
0
7701
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7924
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8130
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7677
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6284
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5219
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3653
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3643
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1223
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.