|
-
Mar 12th, 2010, 11:42 AM
#1
Thread Starter
Member
Read / Write Access Tables
So I have a database in Microsoft Access (its path is c:\database.mdb). There are two tables. Table1 and Table2. I would like to read each row of Table1 to an array, and write a row to Table2.
I have looked all over google, but I couldn't find anything that worked.
-
Mar 12th, 2010, 11:48 AM
#2
Re: Read / Write Access Tables
So what have you tried so far? Do you expect us to do it for you?
Sometimes the Programmer
Sometimes the DBA
Mazz1
-
Mar 12th, 2010, 12:05 PM
#3
Thread Starter
Member
Re: Read / Write Access Tables
I have tried:
http://www.startvbdotnet.com/ado/msaccess.aspx
http://www.java2s.com/Code/VB/Databa...sdatatable.htm
http://www.daniweb.com/forums/thread93667.html#
Dim theOleDbCommand As New OleDbCommand("SELECT Department FROM Table1", New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\database.mdb;"))
theOleDbCommand.Connection.Open()
Dim theReader As OleDbDataReader = theOleDbCommand.ExecuteReader(CommandBehavior.CloseConnection)
While theReader.Read() = True
Console.WriteLine(theReader(0).ToString())
End While
None of those solutions seemed to work for me. The code wouldn't be valid or there would be other errors.
-
Mar 12th, 2010, 12:07 PM
#4
Re: Read / Write Access Tables
So we don't know what errors you got, what you actually typed into the program.....
OK
Have you done the tutorials here (I mean on this forum)?
http://www.vbforums.com/showthread.php?t=337051#Net
Sometimes the Programmer
Sometimes the DBA
Mazz1
-
Mar 12th, 2010, 12:17 PM
#5
Thread Starter
Member
Re: Read / Write Access Tables
 Originally Posted by GaryMazzone
basically I copied and pasted the code that was on the sites and changed the database location / other minor things to make it fit my scenario.
I will take a look at the tutorials now.
-
Mar 12th, 2010, 12:19 PM
#6
Re: Read / Write Access Tables
That is never a good idea. You read and look over the code and try to duplcate it. That way you learn what it is actually doing.
Sometimes the Programmer
Sometimes the DBA
Mazz1
-
Mar 12th, 2010, 03:23 PM
#7
Thread Starter
Member
Re: Read / Write Access Tables
Ok, I figured out the reading part. now using the below code I am trying to write to the database.
vb Code:
Using connection As New OleDbConnection(myConnectionString) Using adapter As New OleDbDataAdapter("SELECT NameFirst, NameLast FROM Employees", _ connection) Dim insert As New OleDbCommand("INSERT INTO Employees (NameFirst, NameLast) VALUES (@NameFirst, @NameLast)", _ connection) adapter.InsertCommand = insert adapter.MissingSchemaAction = MissingSchemaAction.AddWithKey Dim table As New DataTable adapter.FillSchema(table, SchemaType.Source) Dim row As DataRow = table.NewRow() row("NameFirst") = aName(0) row("NameLast") = aName(1) table.Rows.Add(row) adapter.Update(table) End Using End Using
I am getting an error with this line:
adapter.Update(table)
error:
No value given for one or more required parameters.
EDIT: I should note that the first column is auto numbered.
EDIT2: I tried a different table without the auto numbered column and it didn't change anything
Last edited by dethredic; Mar 12th, 2010 at 04:15 PM.
-
Mar 14th, 2010, 06:36 PM
#8
Thread Starter
Member
Re: Read / Write Access Tables
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|