Re: Writing to a MS access db from visual studio .net

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



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" <RobinS@xxxxxxxxxxxxxxx> wrote in message
news:YMudnVcMqrFP5RXYnZ2dnUVZ_oqmnZ2d@xxxxxxxxxxxxxx
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" <bpg24@xxxxxxxxxx> wrote in message
news:1166553451.444061.9220@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
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





.



Relevant Pages

  • Re: ODBC Connection to SQL Server Compact
    ... Sylvain Lafontaine, ing. ... "The database file has been created by an earlier ... The conn object opened "nicely". ... Dim Conn As ADODB.Connection ...
    (microsoft.public.access.modulesdaovba)
  • issues with opening a database
    ... Dim conn As New ADODB.Connection ... Dim strsql As String ... The database has been placed in a state by user 'Admin' on machine ...
    (comp.databases.ms-access)
  • Re: ODBC Connection to SQL Server Compact
    ... "The database file has been created by an earlier ... The conn object opened "nicely". ... Dim Conn As ADODB.Connection ... 'Delete All Records from Mobile Database ...
    (microsoft.public.access.modulesdaovba)
  • Re: ODBC Connection to SQL Server Compact
    ... 1)First the "conn" object opens giving no errors in the error collection.. ... Sylvain Lafontaine, ing. ... "The database file has been created by an earlier ... Dim Conn As ADODB.Connection ...
    (microsoft.public.access.modulesdaovba)
  • Insert/Update tables in a database with relational data from an XML file
    ... on how the heck I can update a database with relational data from an XML ... are loads of info how to update using SetParentRow with ONE parent row ... Dim conn As SqlConnection = New SqlConnection("DataSource... ...
    (microsoft.public.dotnet.xml)