doesnt add new row in access db

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

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()
 
Read this. Ignore what they say about being cautious using "Copy if Newer". It's a crock and that should have been the default. You're about the millionth person to ask this question and all that angst could have been avoided if that was the case.
 
Read the DNU link in my signature..As JMc says, youre the 1,000,001 (sorry you missed out on the grand prize) person to ask this and we all got so sick of answering the Q that I wrote a FAQ about it
 
Back
Top