By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
439,993 Members | 1,947 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 439,993 IT Pros & Developers. It's quick & easy.

Converting a Dataview into a Dataset

P: n/a
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
Share this Question
Share on Google+
6 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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.