Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
DataAdapter Example
Message
From
28/12/2004 18:30:42
 
General information
Forum:
ASP.NET
Category:
ADO.NET
Miscellaneous
Thread ID:
00972709
Message ID:
00972747
Views:
18
Kevin,

You've kind of mixed-and-matched the DataAdapter and OleDbCommand incorrectly.

If you want to use the DataAdapter, it needs to work with a DataSet and you need to execute the DataAdapter.Update() method to send the changes from the DataSet to the backend table.

To just use the OleDbCommand, you would do something like this (this is un-tested and un-compiled code):
Dim cmdInsert As New OleDbCommand("INSERT INTO Products " & _
                     "(product_id, prod_name) VALUES ('KEV1','Kevin1')")
cmdInsert.Connection = MyConnection
cmdInsert.ExecuteNonQuery()
~~Bonnie

>Not sure why this insert doesn't work. It doesn't error at all,
>yet I get no new record into the products table.
>
>
>Imports System.Data.OleDb
>
>Module VFPStuff
>
>    Public Sub VFP1()
>
>        Dim connStr As String = "Provider=VFPOLEDB.1;Data Source=" & _
>                                "c:\program files\microsoft\vfp8\samples\data\testdata.dbc"
>        Dim strSQL As String = "SELECT * FROM Products"
>        Dim oda As New OleDbDataAdapter(strSQL, connStr)
>        Dim cmdInsert As New OleDbCommand("INSERT INTO Products " & _
>                                 "(product_id, prod_name) VALUES ('KEV1','Kevin1')")
>
>        oda.InsertCommand = cmdInsert
>
>        MsgBox("Inserted")
>
>    End Sub
>
>End Module
>
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform