469,275 Members | 1,629 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,275 developers. It's quick & easy.

Converting a Dataview into a Dataset

Hi can any one help me in converting a DataView into a DataSet or a DataTable
into a DataSet,
I tried the following ways

dSet= ((DataSet)_gridRegStudDetails.DataSource);
dSet = ((DataSet)_gridRegStudDetails.DataSource).Tables[0].DataSet;
studData = ((DataSet)dView).Tables[0].DataSet;

But not working
can you pls help me out
Thanks in advance,
N.Ramakrishnan

Nov 21 '05 #1
6 22887
Let's say your dataview's name is myDataView.

myDataView.Table will return to you the underlying DataTable.
"Ramakrishnan Nagarajan" <ra**********@discussions.microsoft.com> wrote in
message news:87**********************************@microsof t.com...
Hi can any one help me in converting a DataView into a DataSet or a
DataTable
into a DataSet,
I tried the following ways

dSet= ((DataSet)_gridRegStudDetails.DataSource);
dSet = ((DataSet)_gridRegStudDetails.DataSource).Tables[0].DataSet;
studData = ((DataSet)dView).Tables[0].DataSet;

But not working
can you pls help me out
Thanks in advance,
N.Ramakrishnan

Nov 21 '05 #2
Ramakrishnan.

A dataview holds no data.

However it holds (in Net 1.x) a reference to its datatable and in 2.0 it
will holds a reference to get its selected/sorted datarowviews.

Therefore what you want you can do in version 2.0. For 1.x you can use this
sample (what is not so much more work).

http://www.windowsformsdatagridhelp....7-d6ad9bebf57f

I hope this helps,

Cor

Nov 21 '05 #3
Ramakrishnan Nagarajan wrote:
Hi can any one help me in converting a DataView into a DataSet or a DataTable
into a DataSet,
I tried the following ways

dSet= ((DataSet)_gridRegStudDetails.DataSource);
dSet = ((DataSet)_gridRegStudDetails.DataSource).Tables[0].DataSet;
studData = ((DataSet)dView).Tables[0].DataSet;

But not working
can you pls help me out
Thanks in advance,
N.Ramakrishnan


You don't convert a datatable to a dataset. You add a table to a dataset.

From the help file under: DataSet Class, adding DataTable

Dim custDS As DataSet = New DataSet("CustomerOrders")

Dim ordersTable As DataTable = custDS.Tables.Add("Orders")

Dim pkCol As DataColumn = ordersTable.Columns.Add("OrderID",
Type.GetType("System.Int32"))
ordersTable.Columns.Add("OrderQuantity", Type.GetType("System.Int32"))
ordersTable.Columns.Add("CompanyName", Type.GetType("System.String"))

ordersTable.PrimaryKey = New DataColumn() {pkCol}
Chris
Nov 21 '05 #4
Hi,
Thanks to every one who have dropped their help for my post.
I have no problem at all in sorting the data in the grid.
At first the DataSet will contain the data from the DataBase. Am fetching
all the data from the DataSet and create a new DataTable along with the new
values entered by the user in the DataGrid. Then Inorder to sort the data am
casting it to a DataView and sorted. Then I am binding the DataView to the
Grid. At this point I want all the data in the DataView to be in the DataSet
for future reference by the same event. So to have all those data in the
DataView to be in the DataSet what can I do. Can you please help me out.
Thanks,
N.Ramakrishnan

"Cor Ligthert [MVP]" wrote:
Ramakrishnan.

A dataview holds no data.

However it holds (in Net 1.x) a reference to its datatable and in 2.0 it
will holds a reference to get its selected/sorted datarowviews.

Therefore what you want you can do in version 2.0. For 1.x you can use this
sample (what is not so much more work).

http://www.windowsformsdatagridhelp....7-d6ad9bebf57f

I hope this helps,

Cor


Nov 21 '05 #5
RamaKrishnan,

Did you see the sample the only thing you need at the end of that is somehow

ds.Add.Tables(dt)
or instead of that
dt = dtnew.copy
ds.Add.Tables(dtnew)

I hope this helps,

Cor
Nov 21 '05 #6
Thanks Cor,
You are right and I did that using ds.Tables.Add(dt);
And now dataset is having the values of the datatable.
Thanks a lot again Cor.

N.Ramakrishnan

"Cor Ligthert [MVP]" wrote:
RamaKrishnan,

Did you see the sample the only thing you need at the end of that is somehow

ds.Add.Tables(dt)
or instead of that
dt = dtnew.copy
ds.Add.Tables(dtnew)

I hope this helps,

Cor

Nov 21 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Arthur Dzhelali | last post: by
3 posts views Thread by Lerp | last post: by
13 posts views Thread by Steve | last post: by
7 posts views Thread by Brett Romero | last post: by
4 posts views Thread by James | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.