[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
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.
Re: [2005] Insert New Access Record
nvrm i just got it to work
can be closed
Re: [2005] Insert New Access Record
you need to mark it resolved
(thread tools menu)
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 :)