Having trouble adding information to the database

vbinuyasha

Member
Joined
Feb 18, 2006
Messages
8
Programming Experience
Beginner
i am having some trouble with my add btn
VB.NET:
[SIZE=2][COLOR=#0000ff]
Private[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2] btnAdd_Click([/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] sender [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.Object, [/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] e [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.EventArgs) [/SIZE][SIZE=2][COLOR=#0000ff]Handles[/COLOR][/SIZE][SIZE=2] btnAdd.Click
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] objRow [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] DataRow
cmd = [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] OleDbCommand[/SIZE][SIZE=2][COLOR=#008000]
[/COLOR][/SIZE][SIZE=2][COLOR=#008000]'Create a new DataRow object for this table
[/COLOR][/SIZE][SIZE=2]objRow = ds.Tables("CarInfo").NewRow()
[/SIZE][SIZE=2][COLOR=#008000]'Edit Each Field value
[/COLOR][/SIZE][SIZE=2]objRow.Item("Make") = txtmake.Text
objRow.Item("Model") = txtmodel.Text
objRow.Item("Color") = txtcolor.Text
objRow.Item("Year") = txtyear.Text
[/SIZE][SIZE=2][COLOR=#008000]'Officially add the DataRow to our table[/COLOR][/SIZE]
[SIZE=2][COLOR=red]---------------------------------------------[/COLOR]
[/SIZE][SIZE=2][COLOR=red]ds.Tables("CarInfo").Rows.Add(objRow)[/COLOR]
[COLOR=red]da.Update(ds, "CarInfo")[/COLOR]
[COLOR=red]cmd.CommandText = "INSERT INTO CarInfo " & "(Make, Model, Color, Year) " & "VALUES (?, ?, ?, ?)"[/COLOR]
[COLOR=red]----------------------------------------------[/COLOR]
ds.AcceptChanges()
[/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub
[/COLOR][/SIZE]

the red code shows where i am having the problem any ideas are welcome thanks
 
You need to read up on ADO.NET. See my signature for some general tutorials that have ADO.NET sections. Do a member search for TechGnome and read the ADO.NET tutorials in his signature.
 
Back
Top