bobo
New member
- Joined
- Feb 9, 2008
- Messages
- 1
- Programming Experience
- Beginner
First off I'm a newbie in vb.net.. I'm trying to insert the data from a textbox and simply inserting it to an Access db. The insert actually works but everytime I rerun my app and try to add new data, the table row won't increase and just kept on overwriting the first row with the new data.
Question is how am I supposed to make it insert into a new row? Thanks
Question is how am I supposed to make it insert into a new row? Thanks
VB.NET:
Dim konek As New OleDb.OleDbConnection
konek.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\dbname.mdb"
konek.Open()
Dim ds As New DataSet
Dim da As OleDb.OleDbDataAdapter
Dim sql As String
sql = "SELECT * FROM TableName"
da = New OleDb.OleDbDataAdapter(sql, konek)
da.Fill(ds, "TableName")
Dim cmdBuilder As New OleDb.OleDbCommandBuilder(da)
' CREATE NEW ROW
Dim row As DataRow
row = ds.Tables("TableName").NewRow()
row.Item("columnname") = value
' ADD ROW TO TABLE
ds.Tables("TableName").Rows.Add(row)
da.Update(ds, "TableName")
konek.Close()