Results 1 to 5 of 5

Thread: [RESOLVED] [2005] Insert New Access Record

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jul 2008
    Posts
    84

    Resolved [RESOLVED] [2005] Insert New Access Record

    I have searched the web and forums for similar problems and tried the solutions they received. I am a noob at databases so any help would be appreciated.

    Right now my app connects to my access database,but I am trying to add a new record to it.

    There are two columns (Account & Username) and on the form two textboxes. I simply need the Account Text box to go into column 1 and Username into Column 2 on the same row.

    Below is what I have right now but I get an error on the last line saying that it can't find the table

    Code:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    
            Dim con As New OleDb.OleDbConnection
            con.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source = C:\Users\Beaver\Documents\Accounts.mdb"
            If con.State = ConnectionState.Open Then
                con.Close()
            End If
            Dim UpdCmd As OleDb.OleDbCommand = New OleDb.OleDbCommand("UPDATE Tabel1 Set Account = ?, Username = ?", con)
            Dim da As OleDb.OleDbDataAdapter = New OleDb.OleDbDataAdapter
            da.UpdateCommand = UpdCmd
            Dim ds As DataSet = New DataSet("Tabel1")
            UpdCmd.Parameters.AddWithValue("@Account", Me.SiteText.Text)
            UpdCmd.Parameters.AddWithValue("@Username", Me.UserText.Text)
            con.Open()
            Dim ret As Integer = UpdCmd.ExecuteNonQuery()
    
        End Sub

  2. #2

    Re: [2005] Insert New Access Record

    Mote the defining of the dataset higher up...that's what I would do.

    I don't know what else to do...It looks fine.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jul 2008
    Posts
    84

    Re: [2005] Insert New Access Record

    nvrm i just got it to work

    can be closed

  4. #4
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,414

    Re: [2005] Insert New Access Record

    you need to mark it resolved
    (thread tools menu)

  5. #5
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: [RESOLVED] [2005] Insert New Access Record

    Hey,

    So the obvious question first, is there a table called Table1 in Accounts.mdb?

    Ok, unless I am missing something, why are you declaring a DataAdapter and a DataSet object, I don't see why you would need either of these in order to perform an update. You would simply do the following:

    Code:
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim con As New OleDb.OleDbConnection
            con.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source = C:\Users\Beaver\Documents\Accounts.mdb"
            If con.State = ConnectionState.Open Then
                con.Close()
            End If
            Dim UpdCmd As OleDb.OleDbCommand = New OleDb.OleDbCommand("UPDATE Tabel1 Set Account = ?, Username = ?", con)
            UpdCmd.CommandType = CommandType.Text
            UpdCmd.Parameters.AddWithValue("@Account", Me.SiteText.Text)
            UpdCmd.Parameters.AddWithValue("@Username", Me.UserText.Text)
            con.Open()
            Dim ret As Integer = UpdCmd.ExecuteNonQuery()
        End Sub
    Hope this helps!!

    Gary

    EDIT: Looks like I was way too late with that post!! Shouldn't try and do two things at once

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