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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Populating a Typed Dataset

Status
Not open for further replies.

anubis7000

Programmer
Apr 27, 2006
19
US
Hi,

I am attempting to populate or fill a typed dataset using the data from my back end ms access database.

I am using this website as a template:


I am stuck at the initilize data function, which is called in the page_load() function. The typed dataset, Dataset1, and the corresponding table, WorkExperianceData are connected to my access database.

Here is my code thus far:

Dim MyRs As New ADODB.Recordset()
Dim MyCn As New ADODB.Connection()
MyCn.Open("Provider=Microsoft.jet.oledb.4.0;data source=d:\workdata.mdb")

MyRs.Open("Select * from WorkExperianceData", MyCn, ADODB.CursorTypeEnum.adOpenStatic, ADODB.LockTypeEnum.adLockOptimistic)

'Create and fill the DataSet from the Recordset. Populate the grid from the DataSet.
Dim myDA As OleDbDataAdapter = New OleDbDataAdapter()
myDA.Fill(DataSet1.WorkExperianceDataDataTable, MyRs, "WorkExperianceData")
DataGrid1.DataSource = DataSet1.Tables(0)

MyRs = Nothing
MyCn.Close()
MyCn = Nothing

Specifically, I am getting errors at the "myDA.Fill...." and the subsequent "DataGrid.Datasource = ..." line, as the compiler says that the use of DataSet is an invalid declaration.

Thanks in advance.
 
1st, your mixing dao objects with ado.net objects. I'm pretty sure they don't work together. No to mention the ado.net is much more effecient on resources.

There are countless examples of filling datasets on the web a simple google search for dataadatper.fill, fill typed dataset, OLEDBAdapter or ado.net will point you in the right direction.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Ok, just to clarify, my typed dataset is already connected to my backend database, so do I still need to fill it? When I preview the data, using xsd editor in vs2005, i can see the data.

I am using the following two lines of code to try to bind the datagrid to the dataset:

DataGrid1.DataSource = _dataSet.WorkExperianceData
DataGrid1.DataBind()

where "_dataset" is of type Dataset1 (my dataset) and WorkExperianceData is my table in Dataset1; however, when I view the webpage, I do not see any data at all.

If anyone has any good links/tutorials concerning this, please post them.

Thanks in advance.
 
you still need to fill your dataset. the dataset doesn't know anything about the database. that's the beauty of the data set, you could change your database to MSSQL, MySQL, an ODBC connection, etc, and the dataset doesn't need to know (provided the results of your query does not change). it only holds data in the model you created at design time.

It's the data adapter that needs to be updated when the database changes. this is the object at connects the database to the application.

you need to use the dataadapter to fill the typed dataset.


Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top