Can't create DataAdapter in code that's available throughout form


In form_load I write the following code:

Dim daC As New OleDbDataAdapter("SELECT * FROM Concepts",
cnConcepts)
dsC.Concepts.Constraints.RemoveAt(1)
daC.Fill(dsC, "Concepts")
dsC.Concepts.ActiveColumn.DefaultValue = True

This Kevin Yu will be familiar with. It fills a series of listboxes with
concepts. In some of the listboxes a New button will appear above the
listbox. Clicking the New button will bring up a form in addnew mode only
for concepts with the proper ParentID. It all works fine.

The problem arises when I want to clear and refill the listboxes, so that
the new entry in the appropriate listbox will show. Here is part of the code
for the appropriate New button.



Dim frm As New frmNewConcept
With frm
'.iNew = Me.lstConcepts0.SelectedValue this is true for all the
others
.iNew = 0
.iNewAddMode = True
.ShowDialog()
End With
If frm.iAddNumber > 0 Then
dsC.Clear()
daC.Fill(dsC, "Concepts")
End If

Of course it won't compile. In the New button I get the message 'Name daC is
not declared'.

I tried declaring daC on the form level


Dim daC As New OleDbDataAdapter("SELECT * FROM Concepts", cnConcepts).

It will compile, but I get the runtime error,

SystemInvalidOperationException. The select command property has not been
initialized before calling 'Fill'.
...
at system.data.common at dbdataadapter.fill(DataSet.dataset, strSourceTable)
...
at TopicFromStart_Load...line 1386

Line 1386
Line 1386 is daC.Fill(dsC, "Concepts")

My question is how do I code a DataApapter in a form so that it fills the
Dataset and also is available to other controls' event procedures.

Thank you in advance.

Dennis

RE: Can't create DataAdapter in code that's available throughout form by polynomial5d

polynomial5d
Sat Oct 23 07:13:02 CDT 2004

I took a shortcut and dragged a oledbdataadapter from the toolbox, named it
daC, and that took care of the problem.

"Dennis" wrote:

> Can't create DataAdapter in code that's available throughout form
>
>
> In form_load I write the following code:
>
> Dim daC As New OleDbDataAdapter("SELECT * FROM Concepts",
> cnConcepts)
> dsC.Concepts.Constraints.RemoveAt(1)
> daC.Fill(dsC, "Concepts")
> dsC.Concepts.ActiveColumn.DefaultValue = True
>
> This Kevin Yu will be familiar with. It fills a series of listboxes with
> concepts. In some of the listboxes a New button will appear above the
> listbox. Clicking the New button will bring up a form in addnew mode only
> for concepts with the proper ParentID. It all works fine.
>
> The problem arises when I want to clear and refill the listboxes, so that
> the new entry in the appropriate listbox will show. Here is part of the code
> for the appropriate New button.
>
>
>
> Dim frm As New frmNewConcept
> With frm
> '.iNew = Me.lstConcepts0.SelectedValue this is true for all the
> others
> .iNew = 0
> .iNewAddMode = True
> .ShowDialog()
> End With
> If frm.iAddNumber > 0 Then
> dsC.Clear()
> daC.Fill(dsC, "Concepts")
> End If
>
> Of course it won't compile. In the New button I get the message 'Name daC is
> not declared'.
>
> I tried declaring daC on the form level
>
>
> Dim daC As New OleDbDataAdapter("SELECT * FROM Concepts", cnConcepts).
>
> It will compile, but I get the runtime error,
>
> SystemInvalidOperationException. The select command property has not been
> initialized before calling 'Fill'.
> ...
> at system.data.common at dbdataadapter.fill(DataSet.dataset, strSourceTable)
> ...
> at TopicFromStart_Load...line 1386
>
> Line 1386
> Line 1386 is daC.Fill(dsC, "Concepts")
>
> My question is how do I code a DataApapter in a form so that it fills the
> Dataset and also is available to other controls' event procedures.
>
> Thank you in advance.
>
> Dennis