Use of datasets in code

jmancuso

Member
Joined
Feb 4, 2005
Messages
22
Programming Experience
1-3
I'm working on my first VB .NET application. I feel I'm using datasets inneffeciently.

In form design I'm adding the connection, adapter, and dataset. This works great for populating controls on form load. However, if I want to populate controls during run time I find myself altering copied code from 'Windows Form Designer Generated Code' and modifying it accordingly. I first clear out the contents of the table(s) in the dataset and then alter the SQL string that I'm passing.

See example:

strSQL = "SELECT * FROM tbl_Sample WHERE ID = 1"

dsSample.tbl_Sample.Clear()

OleDbSelectCommand2.CommandText = strSQL
daSample.InsertCommand = OleDbSelectCommand2
OleDbSelectCommand2.Connection = ODBC
daSample.Fill(DsLoanStatus)


This works but I'm looking for a better way to handle this situation? Is there a way to initialize a new dataset, adapter, etc. during run time?

Thansk for you're help.
 
You mean like this? :
Dim MyDataset as new dataset
Dim MyDataAdapter as new DataAdapter
 
If your first SQL statement is "SELECT * FROM tbl_Sample" and then you only want to filter the data you already have, look into dataViews. They can save you multiple trips to the dataBase and thereby cut down on network traffic and improve response times.
 
Thank you for all your input. In first response I tried declaring the dataset but was unable to declare the dataadapter. So what I tried was after the inherits statment I would declare the command objects. I still felt like this was inefficient.


I've heard of dataviews and since I'm new haven't explored them but the way you described them and what they can do is exactly what I'm looking for!!!

Thanks again for all your help.
 
Back
Top