Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Howto create a Global Dataset

Status
Not open for further replies.

ICTECH

Technical User
Jun 5, 2002
131
CA
Hi Everyone...

I'm stumped, I'm creating a app that requires a Global Dataset to pass data the user selects.
If I create a dataset through a Module, It get an error when I try to manually populate it. The Error is "Object reference not set to an instance of an object."
Can anyone tell me what I'm missing or doing wrong..

Thanks..

<Module Code>

Public Dataset3 As New DataSet("Export")

<App Code>

Dim r as DataRow

r = DataSet3.Tables("Export").NewRow
.
.
.
DataSet3.Tables("Export").Rows.Add(r)
 
Public Dataset3 As New DataSet("Export")

This is creating an instance of the DataSet with name "Export" not the DataTable. DataSet is a collection of DataTable. When you want to add a new row to DataSet, you actually add a new row to the DataTable contained within DataSet.

r = DataSet3.Tables("Export").NewRow

Here you are trying to reference DataTable with name "Export" within DataSet, which is not created.

This is how u can created a DataTable in DataSet. I am assuming you are using SQL Server Database


'Create Connection string.
Dim strConn As String = "Server=YourServer;Database=YourDatabase;User Id=YourUserID;Password=YourPassword"

'Create SQL string.
Dim mySQL As String = "SELECT Field1, Field2,.. FROM Export"

'Initialize SqlDataAdapter with mySQL and Connection String.
Dim mySqlAdapter As SqlDataAdapter = New SqlDataAdapter(mySQL, strConn)

'Create Export DataTable in the DataSet. This will copy the Schema only now.
mySqlAdapter.FillSchema(myDataSet, SchemaType.Mapped, "Export")

'If you want records from the Database table as well use this.
mySqlAdapter.Fill(myDataSet, "Export")


'Now you can add a new row.
Dim r as DataRow

r = myDataSet.Tables("Export").NewRow




 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top