How to make a simple input from VB.net to MS access DB
Posted on 2006-04-11
Hello how is every one doing today?.
Well I just recently jumped into VB and as well as dealing with VB inserting data to an MS Access database.
The problem I have is this....
First and foremost I'm making a simple form which has 1 text box
and 1 button. I just Need to know how to insert the data to the database.
So far Im trying to code it manually instead of using the wizard and I can tell you where I'm stuck at.
I will show the code and then you can tell me what am I doing wrong or what step am I missing.
Dim strConnectionString As String = _
"Provider = Microsoft.Jet.OLEDB.4.0" & _
"Data Source = C:\db2.mdb;"
Dim objConnection As New OleDbConnection(strConnectionString)
'oledbCommand to push SQL statement against the database
Dim txtStr = txtName.Text 'This is the textbox which will receive the input from user
Dim strSQL As String = _
"Insert INTO Names(FName) values (' " & txtStr & " ')"
Dim objCommand As New OleDbCommand(strSQL, objConnection)
'Now to open a connection
Catch OleDbExceptionErr As OleDbException
Catch InvalidOperationExceptionErr As InvalidOperationException
As you can see the code is fairly simple since I'm just trying to see how I can insert data to access, I know I am probably missing a whole
lot of things, or maybe not, but If there is something that I am missing please let me know because I have been stuck on this simple insertion process for
quiet sometime now!! (Sorry big time Noob lol )
Also I wanted to know if the same process I'm doing could also be used to Update, select, and perhaps even delete.
Thankyou for your time guys!!
P.S: Thanks for helping this noob and perhaps other noobs out there :)