Move through dataset and assign to form

banks

Well-known member
Joined
Sep 7, 2005
Messages
50
Programming Experience
Beginner
Hi, i am filling a dataset with the contents of a table based on an sql query (see below) If you can imagine, i have textboxes on the form, which i want to bind to the results inside the dataset. ie, the second column in tblCar is carNo, so i want the carNo to be displayed in txtCarNo. This goes on for all the columns.

I want to somewhat replicate how access forms work, so the user can use buttons to scroll through the record set. I am unsure on how this would work, do i need a for each loop? very unsure of syntax for this...

VB.NET:
Public Sub selectRecords()
        Dim sql As String = "SELECT * FROM tblCar"
        Dim conn As OleDbConnection = carDba.getCn
        Dim da As OleDbDataAdapter = New OleDbDataAdapter(sql, conn)
        Dim ds As DataSet = New DataSet
        da.Fill(ds, "returnedCars")
End Sub

Please could you guys advise me on a) how to bind specific parts of data from the dataset to controls on my form, and b) how i can scroll through the recordset by using buttons i.e. one going previous and one next(even first and last would be good)

Any good tutorials out there, let me know...

Cheers, kind regards,

Alex
 
Checkout the dataform wizard. Once you use it you can take a look at the code it produces and adapt it to your needs. Also if you drag a dataset onto your form at design time and add the neccessary tables,columns etc you can do all the binding at design time too.
 
tutorials can be found by googling for "data walkthroughs" and looking for microsoft in theresults

be aware some results may be vs2005 only
 
RE: Default Move through dataset and assign to form

Hi,

You need to study about the Binding Context object. To change the current location in a DataTable, use the BindingContext object. This object is a property of the form and keeps track of the current position in each Datatable of each DataSet. There is a curreny manager object for each DataTable and the BindingContext object keeps track of all the currencymanager objects.

To specify the appropriate bindingcontext object, pass the name of the DataSet an dthe name of a table in the DataSet as the arguments. The most important property of the BindingContext object is the position property which is the current position in the table. For example, The current position in the accounts DataTable of the the DataSet object is:

VB.NET:
Me.BindingContext(myDataSet,"AccountsTable").Position

Want to know the full implementation, Log on to http://www.vkinfotek.com and see the articles on this topic.

Regards
bhar
 
Last edited by a moderator:
Back
Top