Hello all,
I was wondering if anyone out there would be willing to help me with my problem. All I'm trying to do is add records through text boxes to an access database by pushing a button. I am using Visual Studio.NET 2003 and access 2003.
This is the code that i have thus far:
Imports System.Data.OleDb
Public Class NewUserInfo
Inherits System.Windows.Forms.Form
Dim cn As OleDbConnection
Dim cmd As OleDbCommand
Dim dr As OleDbDataReader
Dim icount As Integer
Dim str As String
Private Sub btnCreate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCreate.Click
Try
cn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\nick\My Documents\Capstone\Users.mdb;")
cn.Open()
str = "insert into Personal (UserName, Password) values ('" & txtNewUserName.Text & "','" & txtNewUserPW.Text & "')"
cmd = New OleDbCommand(str, cn)
icount = cmd.ExecuteNonQuery()
MessageBox.Show(icount)
'displays number of records inserted
Catch ex As Exception
MessageBox.Show(ex.ToString())
End Try
cn.Close()
End Sub
End Class
The exception keeps getting thrown. Can anybody tell me why or have any suggestions?
Any help would be greatly Appreciated. Thanks
I was wondering if anyone out there would be willing to help me with my problem. All I'm trying to do is add records through text boxes to an access database by pushing a button. I am using Visual Studio.NET 2003 and access 2003.
This is the code that i have thus far:
Imports System.Data.OleDb
Public Class NewUserInfo
Inherits System.Windows.Forms.Form
Dim cn As OleDbConnection
Dim cmd As OleDbCommand
Dim dr As OleDbDataReader
Dim icount As Integer
Dim str As String
Private Sub btnCreate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCreate.Click
Try
cn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\nick\My Documents\Capstone\Users.mdb;")
cn.Open()
str = "insert into Personal (UserName, Password) values ('" & txtNewUserName.Text & "','" & txtNewUserPW.Text & "')"
cmd = New OleDbCommand(str, cn)
icount = cmd.ExecuteNonQuery()
MessageBox.Show(icount)
'displays number of records inserted
Catch ex As Exception
MessageBox.Show(ex.ToString())
End Try
cn.Close()
End Sub
End Class
The exception keeps getting thrown. Can anybody tell me why or have any suggestions?
Any help would be greatly Appreciated. Thanks