Results 1 to 8 of 8

Thread: Read / Write Access Tables

  1. #1

    Thread Starter
    Member
    Join Date
    Mar 2010
    Posts
    58

    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.

  2. #2
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    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

  3. #3

    Thread Starter
    Member
    Join Date
    Mar 2010
    Posts
    58

    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.

  4. #4
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    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

  5. #5

    Thread Starter
    Member
    Join Date
    Mar 2010
    Posts
    58

    Re: Read / Write Access Tables

    Quote Originally Posted by GaryMazzone View Post
    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
    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.

  6. #6
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    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

  7. #7

    Thread Starter
    Member
    Join Date
    Mar 2010
    Posts
    58

    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:
    1. Using connection As New OleDbConnection(myConnectionString)
    2.             Using adapter As New OleDbDataAdapter("SELECT NameFirst, NameLast FROM Employees", _
    3.                                               connection)
    4.                 Dim insert As New OleDbCommand("INSERT INTO Employees (NameFirst, NameLast) VALUES (@NameFirst, @NameLast)", _
    5.                                            connection)
    6.                 adapter.InsertCommand = insert
    7.                 adapter.MissingSchemaAction = MissingSchemaAction.AddWithKey
    8.  
    9.                 Dim table As New DataTable
    10.                 adapter.FillSchema(table, SchemaType.Source)
    11.                 Dim row As DataRow = table.NewRow()
    12.  
    13.                 row("NameFirst") = aName(0)
    14.                 row("NameLast") = aName(1)
    15.                 table.Rows.Add(row)
    16.  
    17.                 adapter.Update(table)
    18.             End Using
    19.         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.

  8. #8

    Thread Starter
    Member
    Join Date
    Mar 2010
    Posts
    58

    Re: Read / Write Access Tables

    anyone?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width