VB.net - Insert row using OleDbDataAdapte

Joined
Sep 11, 2008
Messages
1
Reaction score
0
Hello,

I have been trying to make a method to insert a new row in an Access db
using vb.net. Nothing happend in the database after i run the method but I
dont get any error message, so I have no idea what im doing wrong.

Would be very happy if somone can point out how stupid i am, and give me
a little help on the way :)

----------------------------------------------

Public Sub createOrder()

Dim dsOrder As New DataSet("Orders")

Try
'connectionString to db
Dim strConn As String = "Provider = Microsoft.Jet.OLEDB.4.0;" & _
" Data Source = G:\IK1001\Labb_2\Db\App_Data\Northwind.mdb; Persist Security Info = False;"

'create connection objekt with connectionString
Dim conConn As OleDbConnection = New OleDbConnection(strConn)

'open db
conConn.Open()

'create adapter
Dim adpOrder As OleDbDataAdapter = New OleDbDataAdapter("Select * From Orders", conConn)

'fill ds
adpOrder.Fill(dsOrder)

'create new row
Dim dr As DataRow
dr = dsOrder.Tables(0).NewRow

dr(0) = 80
dr(1) = "Peach"
dr(2) = 15
dr(3) = 4
dr(4) = "24 - 150 g jars"
dr(5) = 15
dr(6) = 5
dr(7) = 0
dr(8) = 0
dr(9) = 0

'add row to ds
dsOrder.Tables(0).Rows().Add(dr)

'Update the adapter
adpOrder.Update(dsOrder.GetChanges())

'Align in-memory data with the data source ones
dsOrder.AcceptChanges()
conConn.Close()

Catch ex As Exception
' Reject DataSet changes
dsOrder.RejectChanges()
Console.WriteLine(ex.Message)
End Try
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,812
Latest member
GracielaWa

Latest Threads

Top