Converting a Dataview into a Dataset

G

Guest

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
 
M

Marina

Let's say your dataview's name is myDataView.

myDataView.Table will return to you the underlying DataTable.
 
C

Chris

Ramakrishnan said:
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
 
G

Guest

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
 
C

Cor Ligthert [MVP]

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
 
G

Guest

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top