473,387 Members | 1,619 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,387 software developers and data experts.

Simple Data UPdae Question

I have a very simple Access data base. No new info is going to be
added...the only changes are to existing fields. I have 2 tables both with
one row each. I'm using vb.net.

I can easily retrieve the data via "Reader"...but how to I update for changes?

Thanks
Nov 22 '06 #1
6 1254
Use a DataSet instead of a DataReader.

Robin S.
----------------------------
"Arne Beruldsen" <Ar***********@discussions.microsoft.comwrote in message
news:02**********************************@microsof t.com...
>I have a very simple Access data base. No new info is going to be
added...the only changes are to existing fields. I have 2 tables both
with
one row each. I'm using vb.net.

I can easily retrieve the data via "Reader"...but how to I update for
changes?

Thanks

Nov 22 '06 #2
What would that line(s) of code look like...

I have something that starts like this:

Dim AdConn As New OleDbConnection(CX)
AdConn.Open()

SQL = "Select * from Admin"
Dim AdCommand As New OleDbCommand(SQL, AdConn)
Dim AdDataSet As New DataSet

Dim AdAdapter As New OleDbDataAdapter(SQL, AdConn)
AdAdapter.Fill(AdDataSet, "Admin")

I'm not sure what do to after this...the field in question is titled
password...

Thanks
"RobinS" wrote:
Use a DataSet instead of a DataReader.

Robin S.
----------------------------
"Arne Beruldsen" <Ar***********@discussions.microsoft.comwrote in message
news:02**********************************@microsof t.com...
I have a very simple Access data base. No new info is going to be
added...the only changes are to existing fields. I have 2 tables both
with
one row each. I'm using vb.net.

I can easily retrieve the data via "Reader"...but how to I update for
changes?

Thanks


Nov 22 '06 #3
What version of .Net are you using? VB2005 or is it 2003?

Robin S.

"Arne Beruldsen" <Ar***********@discussions.microsoft.comwrote in message
news:A1**********************************@microsof t.com...
What would that line(s) of code look like...

I have something that starts like this:

Dim AdConn As New OleDbConnection(CX)
AdConn.Open()

SQL = "Select * from Admin"
Dim AdCommand As New OleDbCommand(SQL, AdConn)
Dim AdDataSet As New DataSet

Dim AdAdapter As New OleDbDataAdapter(SQL, AdConn)
AdAdapter.Fill(AdDataSet, "Admin")

I'm not sure what do to after this...the field in question is titled
password...

Thanks
"RobinS" wrote:
>Use a DataSet instead of a DataReader.

Robin S.
----------------------------
"Arne Beruldsen" <Ar***********@discussions.microsoft.comwrote in
message
news:02**********************************@microso ft.com...
>I have a very simple Access data base. No new info is going to be
added...the only changes are to existing fields. I have 2 tables both
with
one row each. I'm using vb.net.

I can easily retrieve the data via "Reader"...but how to I update for
changes?

Thanks



Nov 22 '06 #4

2005

"RobinS" wrote:
What version of .Net are you using? VB2005 or is it 2003?

Robin S.

"Arne Beruldsen" <Ar***********@discussions.microsoft.comwrote in message
news:A1**********************************@microsof t.com...
What would that line(s) of code look like...

I have something that starts like this:

Dim AdConn As New OleDbConnection(CX)
AdConn.Open()

SQL = "Select * from Admin"
Dim AdCommand As New OleDbCommand(SQL, AdConn)
Dim AdDataSet As New DataSet

Dim AdAdapter As New OleDbDataAdapter(SQL, AdConn)
AdAdapter.Fill(AdDataSet, "Admin")

I'm not sure what do to after this...the field in question is titled
password...

Thanks
"RobinS" wrote:
Use a DataSet instead of a DataReader.

Robin S.
----------------------------
"Arne Beruldsen" <Ar***********@discussions.microsoft.comwrote in
message
news:02**********************************@microsof t.com...
I have a very simple Access data base. No new info is going to be
added...the only changes are to existing fields. I have 2 tables both
with
one row each. I'm using vb.net.

I can easily retrieve the data via "Reader"...but how to I update for
changes?

Thanks


Nov 22 '06 #5
First, create a strongly-typed dataset using the DataSet Designer.
You can click on Data/AddNewDataSource and follow the wizard.

This generates a bunch of code for you behind the scenes, including
the data adapter. If you want to look at the code, select your
project, then hit the icon ShowAllFiles in the Solution Explorer.
Then look at the xxDataSet.Designer.vb code, where xxDataSet
is whatever you called your dataset when you created it.

My strongly-typed dataset is called CarriersDataSet. I set this to
point to my a table in my database called "Carriers". The following
code opens the dataset, reads through each row and changes the
field "c_Carrier" in each row, then after doing that, saves the changes.

Dim ds As CarriersDataSet = New CarriersDataSet
Dim adapter As CarriersTableAdapter = New CarriersTableAdapter
adapter.Fill(ds.Carriers)
Dim dt As DataTable = DirectCast(ds.Tables(0), DataTable)
For Each dr As DataRow In ds.Tables(0).Rows
Dim Carrier As String = dr.Item("c_Carrier").ToString
Console.WriteLine(String.Format("Carrier = '{0}'", Carrier))
Carrier &= "_x"
dr.Item("c_carrier") = Carrier 'replace the item in the table
Next
adapter.Update(ds) 'update all changes

If you want to do it the hard way, i.e. typing in all the code yourself,
you're on the right track, but you have to write your own update
command objects. Here's the same code as above, the hard way,
but without the update commands.

Dim ConnectionString As String = _
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=yourdatabase.mdb" & _
";Persist Security Info=False;Jet OLEDB"
Dim ds2 As DataSet = New DataSet
Dim conn As OleDbConnection = New OleDbConnection(ConnectionString)
conn.Open()
Dim cmd As OleDbCommand = New OleDbCommand("select * from Carriers", conn)
Dim adapter2 As OleDbDataAdapter = New OleDbDataAdapter(cmd)
adapter2.Fill(ds2, "Carriers")
For Each dr As DataRow In ds2.Tables(0).Rows
Dim Carrier As String = dr.Item("c_Carrier").ToString
Console.WriteLine(String.Format("Carrier = '{0}'", Carrier))
Next
conn.Close()
conn = Nothing

Good luck.
Robin S.
----------------------------------

"Arne Beruldsen" <Ar***********@discussions.microsoft.comwrote in message
news:E1**********************************@microsof t.com...
>
2005

"RobinS" wrote:
>What version of .Net are you using? VB2005 or is it 2003?

Robin S.

"Arne Beruldsen" <Ar***********@discussions.microsoft.comwrote in
message
news:A1**********************************@microso ft.com...
What would that line(s) of code look like...

I have something that starts like this:

Dim AdConn As New OleDbConnection(CX)
AdConn.Open()

SQL = "Select * from Admin"
Dim AdCommand As New OleDbCommand(SQL, AdConn)
Dim AdDataSet As New DataSet

Dim AdAdapter As New OleDbDataAdapter(SQL, AdConn)
AdAdapter.Fill(AdDataSet, "Admin")

I'm not sure what do to after this...the field in question is titled
password...

Thanks
"RobinS" wrote:

Use a DataSet instead of a DataReader.

Robin S.
----------------------------
"Arne Beruldsen" <Ar***********@discussions.microsoft.comwrote in
message
news:02**********************************@microso ft.com...
I have a very simple Access data base. No new info is going to be
added...the only changes are to existing fields. I have 2 tables
both
with
one row each. I'm using vb.net.

I can easily retrieve the data via "Reader"...but how to I update
for
changes?

Thanks



Nov 22 '06 #6
Arne,

If you want to read using a Reader, than you can use the
command.ExecuteNonQuery to update the database.

Be sure that you do using your transact SQL either in a SP or just as text
the proper concurrency checking.

I hope this helps,

Cor

"Arne Beruldsen" <Ar***********@discussions.microsoft.comschreef in
bericht news:02**********************************@microsof t.com...
>I have a very simple Access data base. No new info is going to be
added...the only changes are to existing fields. I have 2 tables both
with
one row each. I'm using vb.net.

I can easily retrieve the data via "Reader"...but how to I update for
changes?

Thanks

Nov 23 '06 #7

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

Similar topics

51
by: Alan | last post by:
hi all, I want to define a constant length string, say 4 then in a function at some time, I want to set the string to a constant value, say a below is my code but it fails what is the correct...
6
by: KevinD | last post by:
assumption: I am new to C and old to COBOL I have been reading a lot (self teaching) but something is not sinking in with respect to reading a simple file - one record at a time. Using C, I am...
1
by: Brian Henry | last post by:
Hello, I was tring to learn socket's (being i never used them before) and have a simple question. I want to create a listner that will get any data recieved and print it out. I've been able to...
0
by: =?Utf-8?B?cGVsZWdrMQ==?= | last post by:
i have a main page of a website with a lot of data. and i am thinking of not using an access to the DB all time but rather read the data from an XML that will be updated (beacuse the data isn't...
4
by: Thomas | last post by:
Hello, I am a CS student and I want to write simple lisp interpreter. The code should be entierly in C. I don't want to use any compiler generators like Bison or Yak, since wrinting this in...
30
by: galiorenye | last post by:
Hi, Given this code: A** ppA = new A*; A *pA = NULL; for(int i = 0; i < 10; ++i) { pA = ppA; //do something with pA
9
by: =?Utf-8?B?S2VsbHk=?= | last post by:
I am from classic asp and learning asp.net. In the past, once I have a recordset retrieved, I can use it wheneve and wherever I want. For example, I know my recordset contains something like...
10
by: Phillip Taylor | last post by:
Hi guys, I'm looking to develop a simple web service in VB.NET but I'm having some trivial issues. In Visual Studio I create a web services project and change the asmx.vb file to this: Imports...
17
by: Chris M. Thomasson | last post by:
I use the following technique in all of my C++ projects; here is the example code with error checking omitted for brevity: _________________________________________________________________ /*...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...
0
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
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,...

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.