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.
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.