Insert records with ADO.net

  • Thread starter Thread starter massimo capetola
  • Start date Start date
M

massimo capetola

I'm a Vb.net beginner developer and I want to insert records in a table(SQL
CE db) with ADO.net. I have wrotten this code :

Dim ConnDB As New SqlServerCe.SqlCeConnection
Dim daMessage As New SqlServerCe.SqlCeDataAdapter("Select * From ReleEV",
ConnDB)
Dim tblMessage As New DataTable("ReleEV")
Dim dsGepda As New DataSet("ReleEV")

ConnDB.ConnectionString = "Data Source=" & G_Path & "\GEPDA.sdf"
ConnDB.Open()

daMessage.Fill(dsGepda, "ReleEV")
tblMessage = dsGepda.Tables("ReleEV")

drCurrent = tblMessage.NewRow()
drCurrent("Num_mess") = 1 'int field
drCurrent("Des") = "Test" 'nvarchar filed

tblMessage.Rows.Add(drCurrent)

I have no errors, but no records are added in my table "ReleEV".
Any suggestions??
 
Looks like you are missing the SqlCeDataAdapter.Update call (this does the
opposite of Fill - ie pushes you datatable back to the db),

--
Jonathan Wells
Product Manager
..NET Compact Framework
http://smardevices.microsoftdev.com

This posting is provided “AS IS” with no warranties, and confers no rights.
 
I have done daMessage.update(tblMessage) after command
tblMessage.Rows.Add(drCurrent), but I have an error!

An other idea??
 
Massimo,

Do you have a command builder with your SqlCeDataAdaper?
If not, here's the sample code from VS help system on how to use it:

Dim myConn As New SqlCeConnection(myConnection)
Dim myDataAdapter As New SqlCeDataAdapter()

myDataAdapter.SelectCommand = New SqlCeCommand(mySelectQuery, myConn)
Dim cb As SqlCeCommandBuilder = New SqlCeCommandBuilder(myDataAdapter)

myConn.Open()

Dim ds As DataSet = New DataSet()
myDataAdapter.Fill(ds, myTableName)

' Code to modify data in DataSet goes here

' Without the SqlCeCommandBuilder this line would fail.
myDataAdapter.Update(ds, myTableName)
myConn.Close()

End Function

If you have command builder and it does not work, could you please provide
me with detailed error description? Thanks.

Best regards,

Ilya

This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
From: "massimo capetola" <[email protected]>
References: <#[email protected]>
 
Back
Top