Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
DataAdapter Example
Message
 
À
28/12/2004 18:30:42
Information générale
Forum:
ASP.NET
Catégorie:
ADO.NET
Divers
Thread ID:
00972709
Message ID:
00973395
Vues:
17
Bonnie,

Thanks for the reply. I got the code below from Cathi Gero's paper 'ADO.NET', and
I've emailed her about it.

I now modified the snippet you gave here for SQL. I get the message 'Unhandled
exception....System error'

' Create a connection
Dim sConnString As String
sConnString = "data source=(local);" & _
"initial catalog=Northwind;" & _
"user id=myuid" & _
"password=mypword"
oConnection = New SqlConnection(sConnString)
oConnection.Open()

Dim sCmdText As String
sCmdText = "insert into employees (employeeid, lastname) values (100, 'marois')"

Dim cmdInsert As New SqlCommand(sCmdText)

cmdInsert.Connection = oConnection
cmdInsert.ExecuteNonQuery()


Any ideas? Thanks!




>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
>>
Everything makes sense in someone's mind
public class SystemCrasher :ICrashable
In addition, an integer field is not for irrational people
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform