473,387 Members | 1,705 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.

Writing to a MS access db from visual studio .net

Hey all,

I have a fairly simple app which goes out to the web to download data.
I want to store this data in a database (1 table, ~8 fields or so). My
program is written in VB.net and works fine to get the data. My
question is, how do I get the data into a database? I want to use
Microsoft Access.

I have seen several articles on using VB.net and ADO.net or Jet to read
data in, but I haven't seen anything to write data out. Can anyone
suggest articles? Thanks,

Brian

Dec 19 '06 #1
7 2401
Hi, I cant really help with adding the data to an access database, but
is there anyway I could have a look at your program? I'm trying to do
something like this myself.
gordy wrote:
Hey all,

I have a fairly simple app which goes out to the web to download data.
I want to store this data in a database (1 table, ~8 fields or so). My
program is written in VB.net and works fine to get the data. My
question is, how do I get the data into a database? I want to use
Microsoft Access.

I have seen several articles on using VB.net and ADO.net or Jet to read
data in, but I haven't seen anything to write data out. Can anyone
suggest articles? Thanks,

Brian
Dec 19 '06 #2
MDB is obsolete; and it has been for a decade

-Aaron
gordy wrote:
Hey all,

I have a fairly simple app which goes out to the web to download data.
I want to store this data in a database (1 table, ~8 fields or so). My
program is written in VB.net and works fine to get the data. My
question is, how do I get the data into a database? I want to use
Microsoft Access.

I have seen several articles on using VB.net and ADO.net or Jet to read
data in, but I haven't seen anything to write data out. Can anyone
suggest articles? Thanks,

Brian
Dec 19 '06 #3
You can use the OLEDB objects
to read and write to an Access database.

Here's an example with VB2005/.Net2.0.

Imports System.Data.Oledb
Dim ConnectionString As String = _
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=E:\myAccessDatabase.mdb;" & _
"Persist Security Info=False"
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
Robin S.
------------------------------
"gordy" <bp***@drexel.eduwrote in message
news:11********************@i12g2000cwa.googlegrou ps.com...
Hey all,

I have a fairly simple app which goes out to the web to download data.
I want to store this data in a database (1 table, ~8 fields or so).
My
program is written in VB.net and works fine to get the data. My
question is, how do I get the data into a database? I want to use
Microsoft Access.

I have seen several articles on using VB.net and ADO.net or Jet to
read
data in, but I haven't seen anything to write data out. Can anyone
suggest articles? Thanks,

Brian

Dec 19 '06 #4
Oh, and here's what you *really* wanted, an example
of writing to Access. (Sorry; it's been a long day.)
To do this, I use the strongly-typed datasets. You can
define one through the DataSet designer.

This goes through and changes all the entries in a table.
(I was just mucking around.) Then it adds 2 rows to the
table just for the heck of it.

Dim ds As CarriersDataSet = New CarriersDataSet
Dim adapter As CarriersTableAdapter = New CarriersTableAdapter
adapter.Fill(ds.Carriers)
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
Next
'one way to add a row
Dim dr2 As DataRow = ds.Carriers.NewRow()
dr2("c_Carrier") = "Robin"
dr2("c_serv_ctr_code") = "RRR"
ds.Carriers.Rows.Add(dr2)
'another way to add a row
ds.Carriers.Rows.Add("SSS", "Scott")
'update the database with the changes to the dataset
adapter.Update(ds)
ds = Nothing

Again, this is VB2005/.Net2.0.

Robin S.
--------------------------------
"RobinS" <Ro****@NoSpam.yah.nonewrote in message
news:YM******************************@comcast.com. ..
You can use the OLEDB objects
to read and write to an Access database.

Here's an example with VB2005/.Net2.0.

Imports System.Data.Oledb
Dim ConnectionString As String = _
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=E:\myAccessDatabase.mdb;" & _
"Persist Security Info=False"
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
Robin S.
------------------------------
"gordy" <bp***@drexel.eduwrote in message
news:11********************@i12g2000cwa.googlegrou ps.com...
>Hey all,

I have a fairly simple app which goes out to the web to download
data.
I want to store this data in a database (1 table, ~8 fields or so).
My
program is written in VB.net and works fine to get the data. My
question is, how do I get the data into a database? I want to use
Microsoft Access.

I have seen several articles on using VB.net and ADO.net or Jet to
read
data in, but I haven't seen anything to write data out. Can anyone
suggest articles? Thanks,

Brian


Dec 20 '06 #5
"gordy" <bp***@drexel.eduwrote in message
news:11********************@i12g2000cwa.googlegrou ps.com...
Hey all,

I have a fairly simple app which goes out to the web to download data.
I want to store this data in a database (1 table, ~8 fields or so). My
program is written in VB.net and works fine to get the data. My
question is, how do I get the data into a database? I want to use
Microsoft Access.

I have seen several articles on using VB.net and ADO.net or Jet to read
data in, but I haven't seen anything to write data out. Can anyone
suggest articles? Thanks,

Brian
Add reference - adodb

'Database variables
Dim sDataPath As String
Dim sAccessDB As String
Dim Conn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim sSQL As String

'Assign the Database
sDataPath = "C:\MyAccessDB.mdb"
sAccessDB = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="
sAccessDB = sAccessDB & sDataPath
sAccessDB = sAccessDB & ";User Id=admin;Password=;"

'Open the Access DB connection
Conn = New ADODB.Connection
Conn.CursorLocation = ADODB.CursorLocationEnum.adUseClient
Conn.ConnectionString = sAccessDB
Conn.Open()

'Write entry to the Access DB
rs = New ADODB.Recordset
rs.CursorLocation = ADODB.CursorLocationEnum.adUseClient
sSQL = "SELECT TOP 1 * FROM tblTableName"
rs.Open(sSQL, Conn, ADODB.CursorTypeEnum.adOpenStatic, _
ADODB.LockTypeEnum.adLockPessimistic)
rs.AddNew()
rs("Field1Name").Value = "Whatever"
rs("Field2Name").Value = "Whatever"
rs("Field3Name").Value = "Whatever"
rs("Field4Name").Value = "Whatever"
rs("Field5Name").Value = "Whatever"
rs("Field6Name").Value = "Whatever"
rs.Update()
rs.Close()
rs = Nothing

'Close the Database connections
Conn.Close()
Conn = Nothing
Dec 20 '06 #6
Gordy,

Create like you see in the samples from the others a databaseconnection and
a oledbcommand.

However don't use an datatable, that is far to much work.

If it is only inserting than create an SQL transact Insert command something
as

Insert into mytable (a,b) as (myId, myfield)

And use than the command.executeNonQuery to process that.

If you want to update tables, than use the sample given by the others.

Cor
"gordy" <bp***@drexel.eduschreef in bericht
news:11********************@i12g2000cwa.googlegrou ps.com...
Hey all,

I have a fairly simple app which goes out to the web to download data.
I want to store this data in a database (1 table, ~8 fields or so). My
program is written in VB.net and works fine to get the data. My
question is, how do I get the data into a database? I want to use
Microsoft Access.

I have seen several articles on using VB.net and ADO.net or Jet to read
data in, but I haven't seen anything to write data out. Can anyone
suggest articles? Thanks,

Brian

Dec 20 '06 #7
I think there are a few million users that would disagree with you
Aaron.
But I see you are spouting your grand words of unqualified wisdom here
like you are in the VB is dead thread also.

aa*********@gmail.com wrote:
MDB is obsolete; and it has been for a decade

-Aaron
gordy wrote:
Hey all,

I have a fairly simple app which goes out to the web to download data.
I want to store this data in a database (1 table, ~8 fields or so). My
program is written in VB.net and works fine to get the data. My
question is, how do I get the data into a database? I want to use
Microsoft Access.

I have seen several articles on using VB.net and ADO.net or Jet to read
data in, but I haven't seen anything to write data out. Can anyone
suggest articles? Thanks,

Brian
Dec 20 '06 #8

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

Similar topics

63
by: Jerome | last post by:
Hi, I'm a bit confused ... when would I rather write an database application using MS Access and Visual Basic and when (and why) would I rather write it using Visual Studio .Net? Is it as easy...
3
by: Greg B | last post by:
Created a simple Win32 application (using Visual Studio wizard)... Am using Visual Studio (Enterprise Edition) 6.0, as well as Service Pack 5. At the start of 'WinMain' function, added the...
1
by: pw | last post by:
Hi, I can't find anything about a toolkit on Microsoft site or what is needed to distribute an Access 2003 application (like the SDK w/ Access 97). I assume this is still possible. What do I...
11
by: olle | last post by:
Hi everyone. I am an Access developer having worked with Access-dev. projects for many years on Sql server databases and Access. For the internet I have been using traditional asp. But now I have...
7
by: Desmond Cassidy | last post by:
Hi, I have being trying to get a grip of HTML data manipulation and am using the mshtml class and System.Net to retriver HTML pages. Now as far as I can see, one can read HTML in different ways....
18
by: surfrat_ | last post by:
Hi, I am having the following problems in getting Microsoft Visual Studio 2005 Professional to link to an Access .mdb database. Please help me to sort this out. Problem 1: The Microsoft...
5
by: Mo | last post by:
Hello all, I'm trying to set up an access 2000 .adp project connecting to a SQL server 2005 database. I can set up the connection ok, but once I have completed the setup process, I get the...
4
by: Cindy H | last post by:
Hi I am currently using Visual Studio.Net 2003 running on Windows Server 2000 operating system. I have used Visual Studio.net 2003 connecting to Access 2002 databases in the pass with great...
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
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:
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
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...

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.