Datagrid and Dataset newbie help!!

mgandha
04-02-2004, 09:04 AM
Im trying to implement a simple lending library interface. I have a database of my collection of items.

I have succesfully queried my access database and slap the data on a datagrid. Ok with this application, i have to be able to search, add, and make changes to the database through widgets and stuff. Is the dataset the best way or the datareader is better?

Also how do I call different statements to this dataset? for example view all items, view only books or music. and update the datagrid? Im asking for the dataset or adaptor code not the sql queries.

Im still pretty much confused about how the ADO.net works, if anyone can give me code examples or recommend me a good book which does extensive exmaples for datagrid , dataset, datareader stuff that would be great. Thanks.

:huh:

MKoslof
04-03-2004, 07:56 AM
Ok, you are a little bit confused regarding the functionality of a dataset. You can't run an query against a DataSet. Consider a DataSet as a container...you CAN access the tables or datarows within a DataSet. So, for a DataGrid, this is the common procedure I use.

1) Create a new DataSet and DataTable
2) Build your DataTable, whether it be from an database file, array, whatever. I tend to also create TableStyles, so I can auto format my grid on the fly and do other formatting stuff (but that is a seperate help issue).
3) Set this dataTable as the source of the DataGrid
4) Also add this dataTable to the DataSet via the myDataSet.Tables.add(dtable) method.

Now, my DataSet contains the table I used for the DataGrid. Now, I can get to this data directly at any time, by accessing the DataSet.Tables collection, such as:



Dim dt as DataRow
Dim strString, strString2 as string

For Each dt In myDataSet.Tables(0).Rows
strString = CStr(dr(1))
strString2 = CStr(dr(2))
Next



So I am accessing the first table within the DataSet and getting each datarow within it..now I can assign this to a string variable, whatever.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum