473,513 Members | 2,709 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Updating Databases in VB.NET

Here's my code...

Private oConn As New OleDb.OleDbConnection()
Private oCommand As New OleDb.OleDbCommand()
Private oDataAdapter As New OleDb.OleDbDataAdapter()
Private oDataSet As New DataSet()

Public Event Err()

Public Sub Init()

Dim Row As DataRow

oConn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=" & Application.StartupPath & "\WinMUX.mdb;Persist Security
Info=False"

oCommand.CommandText = "SELECT Name FROM Objects"
oCommand.Connection = oConn
oCommand.CommandTimeout = 30
oDataAdapter.SelectCommand = oCommand
oDataAdapter.Fill(oDataSet, "Objects")

For Each Row In oDataSet.Tables("Objects").Rows
MsgBox(Row("Name"))
If Row("Name") = "Brimstone" Then
Row("Name") = "NotBrimstone"
End If
Next
oDataAdapter.Update(oDataSet, "Objects")

End Sub

I know it isn't the prettiest code but I'm just trying to figure this Data
Access stuff out in .NET. How do I update the data in the database with
what has been changed in the Dataset? I'm completely lost. With ADO you
used to just call the adoRecordset.Update method. What do you do now?
Andrew Cooper
ae******@earthlink.net
Nov 20 '05 #1
4 1142
"TDS News" <ae******@earthlink.net> schrieb
oDataAdapter.Update(oDataSet, "Objects")
I know it isn't the prettiest code but I'm just trying to figure this
Data Access stuff out in .NET. How do I update the data in the
database with what has been changed in the Dataset? I'm completely
lost. With ADO you used to just call the adoRecordset.Update method.
What do you do now?

The code looks good. I didn't test it but it should work - or does it not?
oDataAdapter.Update should update the data source.
--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #2
Cor
Hi,

I was first thinking the same as Armin and fortunatly I saw it, there was no
commandbuilder. (That makes all kind of commands from your select)
I also added something about haschanges and getchanges, but that is not the
reason why it is not updating, that is just ment as a little bit optimizing.

Watch typos, because I did type it in your style.

I hope this helps,

Cor
Private oConn As New OleDb.OleDbConnection()
Private oCommand As New OleDb.OleDbCommand()
Private oDataAdapter As New OleDb.OleDbDataAdapter() \\
Private oCommandBuilder As OleDbCommandBuilder
// Private oDataSet As New DataSet()

Public Event Err()

Public Sub Init()

Dim Row As DataRow

oConn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=" & Application.StartupPath & "\WinMUX.mdb;Persist Security
Info=False"

oCommand.CommandText = "SELECT Name FROM Objects"
oCommand.Connection = oConn
oCommand.CommandTimeout = 30
oDataAdapter.SelectCommand = oCommand \\
oCommandBuilder = New OleDbCommandBuilder(oDataAdapter)
//
If oDataset.HasChanges Then
da.Update(oDatasetds.GetChanges)
End If
oDataAdapter.Fill(oDataSet.GetChanges, "Objects")
End if
For Each Row In oDataSet.Tables("Objects").Rows
MsgBox(Row("Name"))
If Row("Name") = "Brimstone" Then
Row("Name") = "NotBrimstone"
End If
Next \\
If oDataset.HasChanges Then
oDataAdapter.Update(oDataset.GetChanges,"Objects")
End If
// End Sub

I know it isn't the prettiest code but I'm just trying to figure this Data
Access stuff out in .NET. How do I update the data in the database with
what has been changed in the Dataset? I'm completely lost. With ADO you
used to just call the adoRecordset.Update method. What do you do now?

Nov 20 '05 #3
Cor,

Thanks! That helped a whole lot. I'm finally getting the hang of it.
The CommandBuilder was a huge time saver. I was building every command by
hand and that was very tedious.

Andrew
"Cor" <no*@non.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Hi,

I was first thinking the same as Armin and fortunatly I saw it, there was no commandbuilder. (That makes all kind of commands from your select)
I also added something about haschanges and getchanges, but that is not the reason why it is not updating, that is just ment as a little bit optimizing.
Watch typos, because I did type it in your style.

I hope this helps,

Cor
Private oConn As New OleDb.OleDbConnection()
Private oCommand As New OleDb.OleDbCommand()
Private oDataAdapter As New OleDb.OleDbDataAdapter()

\\
Private oCommandBuilder As OleDbCommandBuilder
//
Private oDataSet As New DataSet()

Public Event Err()

Public Sub Init()

Dim Row As DataRow

oConn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=" & Application.StartupPath & "\WinMUX.mdb;Persist Security
Info=False"

oCommand.CommandText = "SELECT Name FROM Objects"
oCommand.Connection = oConn
oCommand.CommandTimeout = 30
oDataAdapter.SelectCommand = oCommand

\\
oCommandBuilder = New OleDbCommandBuilder(oDataAdapter)
//
If oDataset.HasChanges Then
da.Update(oDatasetds.GetChanges)
End If
oDataAdapter.Fill(oDataSet.GetChanges, "Objects")
End if

For Each Row In oDataSet.Tables("Objects").Rows
MsgBox(Row("Name"))
If Row("Name") = "Brimstone" Then
Row("Name") = "NotBrimstone"
End If
Next

\\
If oDataset.HasChanges Then
oDataAdapter.Update(oDataset.GetChanges,"Objects")
End If
//
End Sub

I know it isn't the prettiest code but I'm just trying to figure this Data Access stuff out in .NET. How do I update the data in the database with
what has been changed in the Dataset? I'm completely lost. With ADO you used to just call the adoRecordset.Update method. What do you do now?


Nov 20 '05 #4
"Cor" <no*@non.com> schrieb

I was first thinking the same as Armin and fortunatly I saw it, there
was no commandbuilder. (That makes all kind of commands from your
select)

Thx. :-)
--
Armin

Nov 20 '05 #5

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

Similar topics

11
16077
by: Jason | last post by:
Let's say I have an html form with 20 or 30 fields in it. The form submits the fields via POST to a php page which updates a table in a database with the $_POST vars. Which makes more sense? ...
3
2766
by: Robin Tucker | last post by:
Hi there, I have a database on my test machine that will need to be installed on users machines. I would like to create the database with the given schema on the users machine and also with...
1
1498
by: Chuckles | last post by:
Ok I am attempting to build a training database that records the employees training required vs. training received. My problem lies in the fact that the jobcode(s) assigned to that employee ...
2
1006
by: Neil | last post by:
I was wondering if anybody could shed some light on this scenario, maybe there is white paper somewhere ? I have a vb.net app that runs on a few machines storing data in a local access db, but...
1
1496
by: davidgordon | last post by:
Hi, If I am updating a list of records for a user on an asp page, is there a way to hold the page updating, even if they refresh the page, until I have updated all the records. i.e. rather...
1
1099
by: Monty | last post by:
Hi, I am using Access for a back-end database. I can't use the automated updating provided for SQL databases, so I need some assistance in writing the code that does the actual updating, deleting...
1
1347
by: RS200Phil | last post by:
Hi, I have managed to create a second copy of my "live" database, for software testing purposes. Inspecting the properties of the new database, everything seems in order. The logical file...
5
2055
by: aaron.m.johnson | last post by:
I have an application which contains an Access database with linked tables that point to another database within the application. The problem I have is that when the user installs the application,...
33
3254
by: bill | last post by:
In an application I am writing the user can define a series of steps to be followed. I save them in a sql database using the field "order" (a smallint) as the primary key. (there are in the range...
0
1051
by: rkreddys | last post by:
Tasks to Move SQL 2000 Databases into Single Server with multiple dabases then Upgrade SQL 2000 to 2005 and Merge multiple databases into single database. How to move Databases over WAN links...
0
7254
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,...
0
7153
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7373
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,...
0
5677
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,...
1
5079
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3230
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...
0
3218
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
796
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
452
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.