I created a new query and it works fine by calling .FillByProjectNum (name I gave it). But I don't understand how I can do it without a dataset. One of the parameters for .FillBy... is a datatable, but I have to use the dataset to reference it:
Me.TblNotesTableAdapter.FillByProjectNum(Me.NotesDataSet.tblNotes, FindNotes)
So how do I reference the datatable without the dataset? You'll have to excuse me if this sounds noobish because I am
.
Oh.. erm. Let me explain a few things:
A DataSet is a collection of DataTables. Within a typed dataset you have named access to the data tables. In a non typed dataset it behaves more like a classic collection that is indexed by nuimbers or strings:
myTypedDataSet.tblNotes
myUntypedDataSet.Tables("tblNotes")
Both these lines of code return some form of datatable. When using a Typed dataset, we get a typed DataTable back. Specifically the type of the data table in the former case is that of tblNotesDataTable
In the latter case, we just get a generic DataTable back
The advantage of using typed vs untyped objects is that we can get things right at design time and also be specific about what we want our objects to be. You might not notice if you have a setting called Option Explicit turned off but if it is turned on (recommended as it encourages precise and clear thinking hence better programming) the following two statements, only one would work:
'increment SomeIntegerColumn in the first row of the table, by 1
myTypedDataSet.myTypedDataTable(0).SomeIntegerColumn += 1
[U]myUntypedDataSet.Tables("myUntypedDataTable").Rows(0).Item("SomeIntegerColumn") += 1[/U]
[U]
[/U]
The second item fails with a wiggly line because everything on the left of the += is a path to an object that is simply of type Object
It is not possible to add 1 to an object - Object could be Anything, a string, a textbox, an HTTPDataStream etc..
To get the latter code to work would require this, more messy code:
DirectCast(myUntypedDataSet.Tables("myUntypedDataTable").Rows(0).Item("SomeIntegerColumn"), Integer) += 1
i.e. we would have to remember that the item is an integer, and we have to cast it before the compiler will be satisfied we know what we are doing
So the lessons?
Typed is better then untyped. Always try to use typed objects
(typed) DataSets are collections of (typed) DataTables
DataSets also hold and maintain relationships and these are useful later
(typed) DataTables are collections of (typed) DataRows
DataRows are like arrays - fixed number of cells
Typed stuff (generated by the IDE at least) usually has nice things like named properties you can use to make your code neat, readable and self-documenting.
Now to the next part of your question:
When you drag and drop a datatable out of the Data Sources window in the IDE< and drop it on a form, the IDE investigates what dataset that table is a member of. it is the entire DataSet that is added to the form, and the controls are linked to the dataset but they have an additional property set called DataMember - this is a string property that points the component to the right table in the set.
So your form has a DataSet on it rather than a DataTable. This is necessary because if you have things on your form, likle customer details and all that customer's order info then you *want* them to be there as part of a dataset. that way, any relations you have drawn into the set get activated and used..
Thus, we are happy that a DataSet is a collection of DataTables, and we are also happy that our form has a DataSet on it..
We come to the point about having to use a DataSet in the fillby, whereas I said you have to use a datatable..
In your code:
Me.NotesDataSet.
tblNotes
Me refers to the form
.NotesDataSet refers to the dataset on the form
.tblNotes refers to the tblNotes DataTable within the dataset
So dont worry.. we are still passing a datatable to the fillby, the dataset keeps hold of it too, and when FIll has finished it is full of data, still within the dataset, on the form and accessible in your form's code
You naturally have to use the dataset because thats the only thing you have a reference to, that has a reference to the datatable you want to fill
I find it helps me to picture objects as balls, and references asbits of string with a tag on the end. I have a form-ball and stuck to it is a bit of paper with NotesDataSet written on. Tied to the paper is a bit of string that leads to another ball that represents my dataset. that too has several bits of paper one of which says tblNotes, and that paper is strung to the notes table ball:
(Form object called [B]Me[/B])[NotesDataset]---------(A NotesDataSet object)[tblNotes]--------(a tblNotesDataTable object)
If i said in the main form code:
Dim x as tblNotesDataTable = Me.NotesDataSet.tblNotes
i would have this:
(Form object called Me)[NotesDataset]---------(A NotesDataSet object)[tblNotes]--------(a tblNotesDataTable object)
|
(Form object called Me)[x]-----------------------------------------------------------------+
a bit of paper tag with X written on, tied directly to the tblNotes datatable..
I could pass that in to the fillby and it would fill the same dataset