MS Access

Discussion in 'ASP.NET / ASP.NET Core' started by J.Bey, Apr 7, 2006.

Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.
  1. Dim adapter As New OleDb.OleDbDataAdapter
    Dim data As New DataSet
    Dim row As DataRow
    ' connection string is not declared...
    Dim dbconn As System.Data.OleDb.OleDbConnection
    ' I think you mean to declare selection here
    Dimselection As String

    dbconn.Open()
    selection= "SELECT * FROM Accounts;"
    adapter.SelectCommand = New System.Data.OleDb.OleDbCommand(selection, dbconn)
    ' I believe that's how we handle error exception in Classic ASP
    ' Try use "Try & Catch" block instead
    ' ie, Try
    ''code to exec.
    Catch Exc As Exception
    '' code to handle error exceptions
    ' End Try
    On Error Resume Next
    adapter.Fill(data)
    On Error GoTo -1
    row = data.Tables(0).NewRow()
    row("FirstName") = txtFirstName.Text
    row("LastName") = txtLastName.Text
    row("EmailAddress1") = txtEmail.Text
    row("LoginID") = "newuser"
    row("Password") = "1111"
    data.Tables(0).Rows.Add(row)
    'try replace update method with UpdateCommand(cmdstring, dbconn)
    adapter.Update(data)
    dbconn.Close()


    Jason
    Technical Support/IT Admin/MIS Developer
    Maxtop Enterprises Inc.
    http://www.maxtop.ca</CODE>
     
  2. I am attempting to insert a new record into a MS Access DB.

    I do not get an error message, but the new record does not show up. I have verified communication with my database by looking up users, etc. (when they're already in the DB)
    Here is my code:

    Dim adapter As New OleDb.OleDbDataAdapter
    Dim data As New DataSet
    Dim row As DataRow
    Dim dbconn As System.Data.OleDb.OleDbConnection
    Dim filter As String

    dbconn.Open()
    filter = "SELECT * FROM Accounts"
    adapter.SelectCommand = New System.Data.OleDb.OleDbCommand(selection, dbconn)
    On Error Resume Next
    adapter.Fill(data)
    On Error GoTo -1
    row = data.Tables(0).NewRow()
    row("FirstName") = txtFirstName.Text
    row("LastName") = txtLastName.Text
    row("EmailAddress1") = txtEmail.Text
    row("LoginID") = "newuser"
    row("Password") = "1111"
    data.Tables(0).Rows.Add(row)
    adapter.Update(data)
    dbconn.Close()

    Thanks for any help.
     
  3. Thanks for the reply. I turns out that I was using an access keyword in my SQL that was causing my statement not to execute. I named one of my fields "password", after changing this your suggestion worked. I ended up using my own INSERT command as you suggested. Again, much appreciated.

    Dave
     
  4. [​IMG]You're welcome!

    [​IMG]I forgot to tell you that ....checking MS Access reserved keywords..

    Jason
    Technical Support/IT Admin/MIS Developer
    Maxtop Enterprises Inc.
    http://www.maxtop.ca</CODE>
     
Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.

Share This Page