I think what I'm trying to do is something relatively simple. I have
created a DataTable using the SQLDataAdapter.Fill method:
Dim da As New SqlDataAdapter("SELECT * FROM Trans", cn)
Dim ds As New DataSet
da.Fill(ds, "AllTrans")
I am currently editing the table records individually by selecting a
subset of the data using a DataView and using the DataRowView.BeginEdit
and DataRowView.EndEdit methods. For example:
Dim dv As New DataView(ds.Tables("AllTrans"))
dv.RowFilter = "A1 = 'ABC'"
Dim drv As DataRowView
For Each drv In dv
drv.BeginEdit()
drv("S1") = "NC"
drv.EndEdit()
Next
However I would like to instead update the DataSet using the equivalent
of an update statement, e.g. "UPDATE AllTrans SET S1 = 'NC' WHERE A1 =
'ABC'".
I am not trying to update the original data source.
Thanks. 7 1126
Hi,
No, there is no such functionality in ado.net.
I think someone posted a notice in this newsgroup about a product that
supports sql statements over DataSet few days or weeks ago.
--
Miha Markic [MVP C#] - RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/
SLODUG - Slovene Developer Users Group www.codezone-si.info
<sk*******@hotmail.com> wrote in message
news:11*********************@g49g2000cwa.googlegro ups.com... I think what I'm trying to do is something relatively simple. I have created a DataTable using the SQLDataAdapter.Fill method:
Dim da As New SqlDataAdapter("SELECT * FROM Trans", cn) Dim ds As New DataSet da.Fill(ds, "AllTrans")
I am currently editing the table records individually by selecting a subset of the data using a DataView and using the DataRowView.BeginEdit and DataRowView.EndEdit methods. For example:
Dim dv As New DataView(ds.Tables("AllTrans")) dv.RowFilter = "A1 = 'ABC'" Dim drv As DataRowView For Each drv In dv drv.BeginEdit() drv("S1") = "NC" drv.EndEdit() Next
However I would like to instead update the DataSet using the equivalent of an update statement, e.g. "UPDATE AllTrans SET S1 = 'NC' WHERE A1 = 'ABC'".
I am not trying to update the original data source.
Thanks.
Skyjoker,
This looks strange to me, why are you not just getting a datatable that you
have to update using a "where" clause in the Select. Seems for me much
easier and cost much less time on the server, on the used network and in the
used computer..
Just my thought,
Cor
Thanks Miha. It's unfortunate that it can't be done through ado.net.
Hi Cor,
I'm currently doing it this way because I have numerous updates that I
want to do to the data, based on more complex criteria. I want to end
up with one DataTable that contains all of the original data with the
various updates applied.
Rick,
However what do you think that the processing behind the scene will be with
that SQL select command that you propose.
It will probably be very much less efficient as what you are doing now.
Just my thought,
Cor
<sk*******@hotmail.com> wrote in message
news:11*********************@g49g2000cwa.googlegro ups.com... I think what I'm trying to do is something relatively simple. I have created a DataTable using the SQLDataAdapter.Fill method:
Dim da As New SqlDataAdapter("SELECT * FROM Trans", cn) Dim ds As New DataSet da.Fill(ds, "AllTrans")
I am currently editing the table records individually by selecting a subset of the data using a DataView and using the DataRowView.BeginEdit and DataRowView.EndEdit methods. For example:
Dim dv As New DataView(ds.Tables("AllTrans")) dv.RowFilter = "A1 = 'ABC'" Dim drv As DataRowView For Each drv In dv drv.BeginEdit() drv("S1") = "NC" drv.EndEdit() Next
However I would like to instead update the DataSet using the equivalent of an update statement, e.g. "UPDATE AllTrans SET S1 = 'NC' WHERE A1 = 'ABC'".
I am not trying to update the original data source.
Thanks.
Maybe you can write yourself a sub, something like
UpdateTable(DTable, Filter, FieldName, NewValue)
with the same code structure you have above.
If there was such a SQL function for a DataTable, it would be doing essentially
the same thing.
Use case in select statement, it will make your code more efficient.
SELECT Case WHEN A1 = 'ABC' THEN 'NC' ELSE A1 END as A1
FROM Trans
This way you don't have to update the datatable.
Thanks
Nilesh This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: PAUL EDWARDS |
last post by:
I have a windows form that is bound to a datatable. In VB6
I could just update the field contents and it would be
updated in the database, however if I update the text
property of the control from...
|
by: Niyazi |
last post by:
Hi,
I have not understand the problem. Before all the coding with few
application everything worked perfectly. Now I am developing Cheque Writing
application and when the cheque is clear the...
|
by: Babu Mannaravalappil |
last post by:
Can somebody please help me figure out why the following method
exceptions out?
Execution at the line marked with ********** hangs for about 15
seconds and then I get an error that says an...
|
by: Mojtaba Faridzad |
last post by:
Hi,
Please check these lines:
DataSet dataSet = new DataSet();
dataAdapter.Fill(dataSet, "mytable");
DataRow row;
row = dataSet.Tables.Rows;
row.BeginEdit();
row = "555";
|
by: Bennett Haselton |
last post by:
Suppose I add a new row to a table in a dataset, and then I use an
OleDbDataAdapter to add that new row to a SQL Server database using
OleDbDataAdapter.Update(), as in the following code:
...
|
by: jaYPee |
last post by:
I have search a lot of thread in google newsgroup and read a lot of
articles but still i don't know how to update the dataset that has 3
tables.
my 3 tables looks like the 3 tables from...
|
by: Richard |
last post by:
Hi,
I have 1 dataset with 2 tables (Table1 as parent, Table2 as Child), 1 row in
both the tables.
I am updating it with a transaction. First parent then child.
When child update fails, it raise...
|
by: Jean Christophe Avard |
last post by:
Hi! I have a dataset that retreive all the item information from the
database. I need to be able to edit them, in the dataset and in the
database.
I have this code, could anyone tell me if I'm...
|
by: PAUL |
last post by:
Hello,
I have 2 tables with a relationship set up in the dataset with vb
..net. I add a new record to the parent table then edit an existing child
record to have the new parent ID. However when I...
|
by: Zorpiedoman |
last post by:
I keep getting a concurrency exception the second time I make a change and
attempt to update a dataadapter. It appears this is by design, so there must
be something I can do to avoid it.
...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
| |