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. 1 1977
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.
<zo****@yahoo.com> wrote in message
news:11**********************@g47g2000cwa.googlegr oups.com... 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. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Tc |
last post by:
Hi,
I was curious, I am thinking of writing an application that loads a dataset
from a database that resides on a server. The question I have is this, if
multiple copies of the app will be...
|
by: Mateusz [PEYN] Adamus |
last post by:
Hi
I have a Typed DataSet.
I've databinded it to some text controls on my form, controls show data
when I show record.
But now I would like to create a new record with this form, controls...
|
by: Rich |
last post by:
Dim da As New SqlDataAdapter("Select * from tbl1", conn)
dim tblx As New DataTable
da.Fill(tblx) '--works OK up to this point
da.UpdateCommand = New SqlCommand
da.UpdateCommand.Connection =...
|
by: Johnny |
last post by:
I have a PocketPC mobile application that gets its data from the Sql Server
database via a web service. The web service returns a dataset that I need to
load into the SqlCe database on the mobile...
|
by: kolalakitty |
last post by:
Hopefully someone here can help me/point me in the right direction.
I've found tons of references towards making relations, creating rows,
saving said rows, using datagrids, databinding objects,...
|
by: fniles |
last post by:
I am using VB.NET 2003, SQL 2000, and SqlDataAdapter.
For every record in tblA where colB = 'abc', I want to update the value in
colA.
In VB6, using ADO I can loop thru the recordset,set the...
|
by: niccolem |
last post by:
HI:
Can someone tell me HOW I can just update 1 row without updating all the data in the column. I think I've confused myself.
Thanks so much
openconnection.open --opens connection to sql...
|
by: Johnny E. Jensen |
last post by:
Hello
To update a dataset i created a method (see below)
My question is, how to return the created Primary ID that is created on the
server auto incremential. Is there anyway to place that value...
|
by: =?Utf-8?B?Y2RtdW5veg==?= |
last post by:
Here's the scenerio: I am importing records into my database through the
program, the first time through the database is empty and so is the dataset.
Everything works fine until the second time...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |