executing sql against a dataset

  • Thread starter Thread starter Noor
  • Start date Start date
N

Noor

Hi all


is there a way to issue sql commands against a dataset.

i mean can we execute an update command on the dataset.

like.. update <datatable> set <somecol> = <somevalue> where <someothercol> =
<someothervalue>


Im not asking about the exact synatax as mentioned above.. but i m just
asking if there is a way to update multiple rows of single col in one go.

thanks

Noor
 
Hi Noor,

Noor said:
Hi all


is there a way to issue sql commands against a dataset.

i mean can we execute an update command on the dataset.

like.. update <datatable> set <somecol> = <somevalue> where <someothercol> =

No.


Im not asking about the exact synatax as mentioned above.. but i m just
asking if there is a way to update multiple rows of single col in one go.

No, but you might consider filtering rows by using either DataTable.Select
method or DataView and then loop on rows and change them as you want.
 
Hi Noor

The answer is no you can not do that directly to the dataset .
you have only the clear method that clear all the data in the dataset.

However there are 2 workarounds to that

1 –

a- write the dataset to an Xml file using the WriteXml method of the
dataset

b- Use the classes of the namespace System.Xml which does allow you to
queries on the xml file

c- clear the dataset using the clear method

d- refill the dataset with the modified Xml file using the ReadXml method
of the dataset

2- do a function that does the querying depending on the input parameters
that are sent to it.



i hope this would be of any help



for example this code do deletion from a table in a dataset depending
on values inside the datarow

myset = new DataSet();

mytable = new DataTable("trial");

mycolumn = new DataColumn("col1" , Type.GetType("System.Decimal"));

mytable.Columns.Add(mycolumn);

DataRow myrow = mytable.NewRow();

myrow["col1"]= 11.1;

mytable.Rows.Add(myrow);

mytable.Rows.Add(new object[]{12.2});

mytable.Rows.Add(new object[]{14.7});

myset.Tables.Add(mytable);

DataRowCollection r = mytable.Rows;




for( int idx = 0; idx < r.Count; idx++ )

{

DataRow row = mytable.Rows[ idx ];

if( row.RowState == DataRowState.Deleted )

{

if( row[ mycolumn, DataRowVersion.Original ].ToString()== "12.2" )

{

r.RemoveAt( idx );

idx--;

}

}

else

{

if( row[ mycolumn].ToString() == "12.2" )

{

r.RemoveAt( idx );

idx--;

}

}

}
 
Hi Noor,

If you want that you can make your own procedure by instance
executedataset(mydataset,selectcolumn, selectstring)

And process that than in the way Miha said.

Cor
 
Noor,
This will be possible to do with ADO.NET 2.0 Whidbey release. Batch
Updates. I would not use Data Adpater for this purpose, just write you own
database mapper to process the updates!

Maxm

[www.ipattern.com do you?]
 
Hi Maxim,

Maxim V. Karpov said:
Noor,
This will be possible to do with ADO.NET 2.0 Whidbey release. Batch
Updates. I would not use Data Adpater for this purpose, just write you own
database mapper to process the updates!

Batch updates mean that adapter will create all necessary (or at least some)
sql commands and batch fire them to server as opposite to now, when one
statament is issued at the time..
 
Back
Top