Updating DataSet using InsertCommand property...


Z

zoneal

I retrieved the following function from VB.NET help and added a few
statements for updating the datasource. But, it does not actually
commence the InsertCommand property of the DataAdapter in order to
physically insert a row into the DataSet. Please help!

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

Public Function CreateCustomerAdapter(ByVal conn As OleDbConnection) As
OleDbDataAdapter

Dim da As OleDbDataAdapter = New OleDbDataAdapter

Dim cmd As OleDbCommand

cmd = New OleDbCommand("SELECT * FROM Customers " & _

"WHERE Country = @Country AND City = @City", conn)

cmd.Parameters.Add("@Country", OleDbType.VarChar, 15).Value = "France"

cmd.Parameters.Add("@City", OleDbType.VarChar, 15).Value = "Paris"

da.SelectCommand = cmd

'---------------------------------------------------

Dim DS As DataSet = New DataSet

da.Fill(DS, "Customers")

DataGrid1.DataSource = DS.Tables("Customers")

Dim CB As OleDbCommandBuilder = New OleDbCommandBuilder(da)

'---------------------------------------------------

cmd = New OleDbCommand("INSERT INTO Customers (CustomerID, CompanyName)
" & _

"VALUES (@CustomerID, @CompanyName)", conn)

cmd.Parameters.Add("@CustomerID", OleDbType.Char, 5,
"CustomerID").Value = "Prime"

cmd.Parameters.Add("@CompanyName", OleDbType.VarChar, 40,
"CompanyName").Value = "Prime IT Solutions"

da.InsertCommand = cmd ' How to implement this command

Dim dt As New DataTable("Customers")

Dim NumRows As Long = da.Update(dt) ' It has no effect on the
DataSet.

MessageBox.Show(NumRows & " Row(s) have been Inserted.", "Inserting
Rows Successful.")

Return da

End Function
'---------------------------------------------------

Thanks in anticipation and regards.
 
Ad

Advertisements

M

Marina

Update is supposed to update the databases with the changes described in the
database. In this case you just created the DataTable. It is empty. There
is nothing to do, nothing to update.
 

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

Top