basic VB.NET database question

Schoolies

Senior member
Oct 9, 1999
495
0
76
All I want to do is take the text from a Visual Basic.NET textbox and put it into an Access database.

I can connect the database to VB, that is not a problem. I just do not know the code to put inside the "Add" button in VB so that it will insert my textbox values as a new record (row) in a table.

VISUAL BASIC.NET and MICROSOFT ACCESSS.... not VB6.... my friend knows VB6 very well and can not figure this out.... strange.

Thanks for the help
 

WannaFly

Platinum Member
Jan 14, 2003
2,811
1
0
I didnt check the attached code, wrote it from memory, but its the basic idea.
 

KB

Diamond Member
Nov 8, 1999
5,406
389
126
Look in the SDK documentation at the System.Data.OleDb namespace. Particularly the OleDbCommand class.

Dim connectString As String
Dim conn As OleDbConnection
Dim dbcom As OleDbCommand

connectString = "Provider=Microsoft.Jet.OleDB.4.0; data source=c:\\db1.mdb";
conn = new OleDbConnection(connectString);

dbcom = new OleDbCommand("insert into table (" + <addbutton>.Text + ")", conn);
dbcom.ExecuteNonQuery()
 

Schoolies

Senior member
Oct 9, 1999
495
0
76
I don't know what's going on with this code. I keep gettign this error message when i click the add buton:

"An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred in system.data.dll".

I put the code you suggested in the button click event procedure.
 

XZeroII

Lifer
Jun 30, 2001
12,572
0
0
A simple way to do it (although it can be slow if you loop it) is like this. I typed this from memory so some minor details or typos may exist, but this is a very straightforward way to do it. The connection string is automatically generated by VB when you do your wizards. Look in the windows generated code for it and copy it in there.

It is definatly not the only way to do it, but it's pretty simple.