Viewing A DataSet Created On The Fly!

A

Arpan

The following code snippet creates a DataSet on the fly which is then passed to a DataView so that the DataSet can finally be viewed in a DataGrid control:

'Create the empty DataSet
Dim objDS As New DataSet("MyDataSet")=CreateDataSet()

'Create the new table & add columns
Dim dTable As New DataTable("Users")
dTable.Columns.Add("ID",System.Type.GetType("System.Int32"))
dTable.Columns.Add("FirstName",System.Type.GetType("System.String"))
dTable.Columns.Add("LastName",System.Type.GetType("System.String"))
dTable.Columns("ID").AutoIncrement=True

'Add the new table to the DataSet's TableCollection
objDS.Tables.Add(dTable)

'Define the Primary Key
Dim dColumn As DataColumn={objDS.Tables("Users").Columns("ID")}
objDS.Tables("Users").PrimaryKey=dColumn

'Add a row to this table
Dim dRow As DataRow=dTable.NewRow()
dRow(1)="Celine"
dRow(2)="Dion"
dTable.Rows.Add(dRow)

Dim objDV As New DataView
objDV.Table=objDS.Tables("Users")
myDataGrid.DataSource=objDV
myDataGrid.DataBind()

Function CreateDataSet
Dim objDS As DataSet=New DataSet("Users")
objDS.Tables.Add(dTable)
Return objDS
End Function

<asp:DataGrid id="myDataGrid" runat=server/>

As such the above code doesn't generate any error but the DataSet isn't getting displayed in the DataGrid! Where am I going wrong?

Please be informed that I am a newbie in ASP.NET & am working on Windows 2000 Professional.

Thanks,

Arpan
 
D

Debasish Bose

1. No need for CreateDataSet() function. You are using New() operator twice - that's wrong.
2. This line
Dim dColumn As DataColumn = {objDS.Tables("Users").Columns("ID")}
should be change to this
Dim dColumn As DataColumn() = {objDS.Tables("Users").Columns("ID")}

Debasish Bose
Silicus Technologies
(e-mail address removed)
The following code snippet creates a DataSet on the fly which is then passed to a DataView so that the DataSet can finally be viewed in a DataGrid control:

'Create the empty DataSet
Dim objDS As New DataSet("MyDataSet")=CreateDataSet()

'Create the new table & add columns
Dim dTable As New DataTable("Users")
dTable.Columns.Add("ID",System.Type.GetType("System.Int32"))
dTable.Columns.Add("FirstName",System.Type.GetType("System.String"))
dTable.Columns.Add("LastName",System.Type.GetType("System.String"))
dTable.Columns("ID").AutoIncrement=True

'Add the new table to the DataSet's TableCollection
objDS.Tables.Add(dTable)

'Define the Primary Key
Dim dColumn As DataColumn={objDS.Tables("Users").Columns("ID")}
objDS.Tables("Users").PrimaryKey=dColumn

'Add a row to this table
Dim dRow As DataRow=dTable.NewRow()
dRow(1)="Celine"
dRow(2)="Dion"
dTable.Rows.Add(dRow)

Dim objDV As New DataView
objDV.Table=objDS.Tables("Users")
myDataGrid.DataSource=objDV
myDataGrid.DataBind()

Function CreateDataSet
Dim objDS As DataSet=New DataSet("Users")
objDS.Tables.Add(dTable)
Return objDS
End Function

<asp:DataGrid id="myDataGrid" runat=server/>

As such the above code doesn't generate any error but the DataSet isn't getting displayed in the DataGrid! Where am I going wrong?

Please be informed that I am a newbie in ASP.NET & am working on Windows 2000 Professional.

Thanks,

Arpan
 

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

Similar Threads


Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top