Home All Groups Group Topic Archive Search About

Problem with DataAdapter Fill method, Ithink

Author
16 Jan 2006 10:24 PM
Joyce
Hi folks,

I am trying to run a simple program to test my data connection.  The
database opens successfully but throws an exception at the
"objDataAdapter.Fill(objDataTabel)" line below.  Am I doing something
thats obviously wrong here?

Thanks,
--Joyce

'---------------------------
Imports System.Data
Imports System.Data.Common
Imports System.Data.OleDb

Public Class Form1
    Dim strConnection As String = _
        "Provider=Microsoft.Jet.OLEDB.4.0;" & _
        "Data Source= C:\Documents and Settings\Trilogy\" & _
        "My Documents\Visual Studio 2005\Projects\dbBackStock.mdb"

    Dim objConnection As New OleDbConnection(strConnection)

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs)

Handles MyBase.Load


        objConnection.Open()

        If objConnection.State = ConnectionState.Open Then
            Label1.Text = "Database is Open"
        Else
            Label1.Text = "Database is Closed"
        End If
    End Sub


    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e
As

System.EventArgs) Handles Button1.Click
        Dim strSQL As String = "SELECT Description, Size FROM
tblProducts"
        Dim objCommand As New OleDbCommand(strSQL, objConnection)
        Dim objDataAdapter As New OleDbDataAdapter(objCommand)
        Dim objDataTabel As New Data.DataTable("Products")
        Dim objDataRow As DataRow

        objDataAdapter.Fill(objDataTabel)    '<----- Exception here


        For Each objDataRow In objDataTabel.Rows
            ListBox1.Items.Add(objDataRow.Item("Description") & " " &
_
                objDataRow.Item("Size"))
        Next

    End Sub
End Class

Author
16 Jan 2006 11:04 PM
I Don't Like Spam
Joyce wrote:

Show quoteHide quote
> Hi folks,
>
> I am trying to run a simple program to test my data connection.  The
> database opens successfully but throws an exception at the
> "objDataAdapter.Fill(objDataTabel)" line below.  Am I doing something
> thats obviously wrong here?
>
> Thanks,
> --Joyce
>
> '---------------------------
> Imports System.Data
> Imports System.Data.Common
> Imports System.Data.OleDb
>
> Public Class Form1
>     Dim strConnection As String = _
>         "Provider=Microsoft.Jet.OLEDB.4.0;" & _
>         "Data Source= C:\Documents and Settings\Trilogy\" & _
>         "My Documents\Visual Studio 2005\Projects\dbBackStock.mdb"
>
>     Dim objConnection As New OleDbConnection(strConnection)
>
>     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
> System.EventArgs)
>
> Handles MyBase.Load
>
>
>         objConnection.Open()
>
>         If objConnection.State = ConnectionState.Open Then
>             Label1.Text = "Database is Open"
>         Else
>             Label1.Text = "Database is Closed"
>         End If
>     End Sub
>
>
>     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e
> As
>
> System.EventArgs) Handles Button1.Click
>         Dim strSQL As String = "SELECT Description, Size FROM
> tblProducts"
>         Dim objCommand As New OleDbCommand(strSQL, objConnection)
>         Dim objDataAdapter As New OleDbDataAdapter(objCommand)
>         Dim objDataTabel As New Data.DataTable("Products")
>         Dim objDataRow As DataRow
>
>         objDataAdapter.Fill(objDataTabel)    '<----- Exception here
>
>
>         For Each objDataRow In objDataTabel.Rows
>             ListBox1.Items.Add(objDataRow.Item("Description") & " " &
> _
>                 objDataRow.Item("Size"))
>         Next
>
>     End Sub
> End Class

It'd be nice to know what your error is...

Chris
Author
16 Jan 2006 11:30 PM
Joyce
Chris, (is top posting ok here?)

The error I receive is "IErrorInfo.GetDescription failed with
E_FAIL(0x80004005)"

--Joyce Perry

On Mon, 16 Jan 2006 18:04:54 -0500, I Don't Like Spam <no@spam.com>
wrote:

Show quoteHide quote
>
>Joyce wrote:
>
>> Hi folks,
>>
>> I am trying to run a simple program to test my data connection.  The
>> database opens successfully but throws an exception at the
>> "objDataAdapter.Fill(objDataTabel)" line below.  Am I doing something
>> thats obviously wrong here?
>>
>> Thanks,
>> --Joyce
>>
>> '---------------------------
>> Imports System.Data
>> Imports System.Data.Common
>> Imports System.Data.OleDb
>>
>> Public Class Form1
>>     Dim strConnection As String = _
>>         "Provider=Microsoft.Jet.OLEDB.4.0;" & _
>>         "Data Source= C:\Documents and Settings\Trilogy\" & _
>>         "My Documents\Visual Studio 2005\Projects\dbBackStock.mdb"
>>
>>     Dim objConnection As New OleDbConnection(strConnection)
>>
>>     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
>> System.EventArgs)
>>
>> Handles MyBase.Load
>>
>>
>>         objConnection.Open()
>>
>>         If objConnection.State = ConnectionState.Open Then
>>             Label1.Text = "Database is Open"
>>         Else
>>             Label1.Text = "Database is Closed"
>>         End If
>>     End Sub
>>
>>
>>     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e
>> As
>>
>> System.EventArgs) Handles Button1.Click
>>         Dim strSQL As String = "SELECT Description, Size FROM
>> tblProducts"
>>         Dim objCommand As New OleDbCommand(strSQL, objConnection)
>>         Dim objDataAdapter As New OleDbDataAdapter(objCommand)
>>         Dim objDataTabel As New Data.DataTable("Products")
>>         Dim objDataRow As DataRow
>>
>>         objDataAdapter.Fill(objDataTabel)    '<----- Exception here
>>
>>
>>         For Each objDataRow In objDataTabel.Rows
>>             ListBox1.Items.Add(objDataRow.Item("Description") & " " &
>> _
>>                 objDataRow.Item("Size"))
>>         Next
>>
>>     End Sub
>> End Class
>
>It'd be nice to know what your error is...
>
>Chris
Author
16 Jan 2006 11:10 PM
Kerry Moorman
Joyce,

The dataadapter's Fill method requires a dataset as the argument, not a
datatable.

Kerry Moorman


Show quoteHide quote
"Joyce" wrote:

>
> Hi folks,
>
> I am trying to run a simple program to test my data connection.  The
> database opens successfully but throws an exception at the
> "objDataAdapter.Fill(objDataTabel)" line below.  Am I doing something
> thats obviously wrong here?
>
> Thanks,
> --Joyce
>
> '---------------------------
> Imports System.Data
> Imports System.Data.Common
> Imports System.Data.OleDb
>
> Public Class Form1
>     Dim strConnection As String = _
>         "Provider=Microsoft.Jet.OLEDB.4.0;" & _
>         "Data Source= C:\Documents and Settings\Trilogy\" & _
>         "My Documents\Visual Studio 2005\Projects\dbBackStock.mdb"
>
>     Dim objConnection As New OleDbConnection(strConnection)
>
>     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
> System.EventArgs)
>
> Handles MyBase.Load
>
>
>         objConnection.Open()
>
>         If objConnection.State = ConnectionState.Open Then
>             Label1.Text = "Database is Open"
>         Else
>             Label1.Text = "Database is Closed"
>         End If
>     End Sub
>
>
>     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e
> As
>
> System.EventArgs) Handles Button1.Click
>         Dim strSQL As String = "SELECT Description, Size FROM
> tblProducts"
>         Dim objCommand As New OleDbCommand(strSQL, objConnection)
>         Dim objDataAdapter As New OleDbDataAdapter(objCommand)
>         Dim objDataTabel As New Data.DataTable("Products")
>         Dim objDataRow As DataRow
>
>         objDataAdapter.Fill(objDataTabel)    '<----- Exception here
>
>
>         For Each objDataRow In objDataTabel.Rows
>             ListBox1.Items.Add(objDataRow.Item("Description") & " " &
> _
>                 objDataRow.Item("Size"))
>         Next
>
>     End Sub
> End Class
>
Author
16 Jan 2006 11:35 PM
Joyce
Kerry,

Ok I read some of the MSDN2 stuff and it appears you can use Fill with
DataTable but I am a newbie. (I used to humm with vb6 but that was 5
years ago)

How would you change my program so that the query results would show
up in the ListBox?  Any help is gratefully appreciated as I've been
stuck here for days!

--Joyce Perry


On Mon, 16 Jan 2006 15:10:02 -0800, "Kerry Moorman"
<KerryMoor***@discussions.microsoft.com> wrote:

Show quoteHide quote
>Joyce,
>
>The dataadapter's Fill method requires a dataset as the argument, not a
>datatable.
>
>Kerry Moorman
>
>
>"Joyce" wrote:
>
>>
>> Hi folks,
>>
>> I am trying to run a simple program to test my data connection.  The
>> database opens successfully but throws an exception at the
>> "objDataAdapter.Fill(objDataTabel)" line below.  Am I doing something
>> thats obviously wrong here?
>>
>> Thanks,
>> --Joyce
>>
>> '---------------------------
>> Imports System.Data
>> Imports System.Data.Common
>> Imports System.Data.OleDb
>>
>> Public Class Form1
>>     Dim strConnection As String = _
>>         "Provider=Microsoft.Jet.OLEDB.4.0;" & _
>>         "Data Source= C:\Documents and Settings\Trilogy\" & _
>>         "My Documents\Visual Studio 2005\Projects\dbBackStock.mdb"
>>
>>     Dim objConnection As New OleDbConnection(strConnection)
>>
>>     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
>> System.EventArgs)
>>
>> Handles MyBase.Load
>>
>>
>>         objConnection.Open()
>>
>>         If objConnection.State = ConnectionState.Open Then
>>             Label1.Text = "Database is Open"
>>         Else
>>             Label1.Text = "Database is Closed"
>>         End If
>>     End Sub
>>
>>
>>     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e
>> As
>>
>> System.EventArgs) Handles Button1.Click
>>         Dim strSQL As String = "SELECT Description, Size FROM
>> tblProducts"
>>         Dim objCommand As New OleDbCommand(strSQL, objConnection)
>>         Dim objDataAdapter As New OleDbDataAdapter(objCommand)
>>         Dim objDataTabel As New Data.DataTable("Products")
>>         Dim objDataRow As DataRow
>>
>>         objDataAdapter.Fill(objDataTabel)    '<----- Exception here
>>
>>
>>         For Each objDataRow In objDataTabel.Rows
>>             ListBox1.Items.Add(objDataRow.Item("Description") & " " &
>> _
>>                 objDataRow.Item("Size"))
>>         Next
>>
>>     End Sub
>> End Class
>>
Author
17 Jan 2006 2:28 AM
Kerry Moorman
Joyce,

I was wrong about the dataadapter's Fill method requiring a dataset. It will
also take a datatable, as you are doing in your code.

I don't see anything obviously wrong with your code. I wonder if either
Description or Size may be reserved words and need to be enclosed in square
brackets in your Select statement:  Select [Description], [Size] From ...

Kerry Moorman


Show quoteHide quote
"Joyce" wrote:

> Kerry,
>
> Ok I read some of the MSDN2 stuff and it appears you can use Fill with
> DataTable but I am a newbie. (I used to humm with vb6 but that was 5
> years ago)
>
> How would you change my program so that the query results would show
> up in the ListBox?  Any help is gratefully appreciated as I've been
> stuck here for days!
>
> --Joyce Perry
>
>
> On Mon, 16 Jan 2006 15:10:02 -0800, "Kerry Moorman"
> <KerryMoor***@discussions.microsoft.com> wrote:
>
> >Joyce,
> >
> >The dataadapter's Fill method requires a dataset as the argument, not a
> >datatable.
> >
> >Kerry Moorman
> >
> >
> >"Joyce" wrote:
> >
> >>
> >> Hi folks,
> >>
> >> I am trying to run a simple program to test my data connection.  The
> >> database opens successfully but throws an exception at the
> >> "objDataAdapter.Fill(objDataTabel)" line below.  Am I doing something
> >> thats obviously wrong here?
> >>
> >> Thanks,
> >> --Joyce
> >>
> >> '---------------------------
> >> Imports System.Data
> >> Imports System.Data.Common
> >> Imports System.Data.OleDb
> >>
> >> Public Class Form1
> >>     Dim strConnection As String = _
> >>         "Provider=Microsoft.Jet.OLEDB.4.0;" & _
> >>         "Data Source= C:\Documents and Settings\Trilogy\" & _
> >>         "My Documents\Visual Studio 2005\Projects\dbBackStock.mdb"
> >>
> >>     Dim objConnection As New OleDbConnection(strConnection)
> >>
> >>     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
> >> System.EventArgs)
> >>
> >> Handles MyBase.Load
> >>
> >>
> >>         objConnection.Open()
> >>
> >>         If objConnection.State = ConnectionState.Open Then
> >>             Label1.Text = "Database is Open"
> >>         Else
> >>             Label1.Text = "Database is Closed"
> >>         End If
> >>     End Sub
> >>
> >>
> >>     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e
> >> As
> >>
> >> System.EventArgs) Handles Button1.Click
> >>         Dim strSQL As String = "SELECT Description, Size FROM
> >> tblProducts"
> >>         Dim objCommand As New OleDbCommand(strSQL, objConnection)
> >>         Dim objDataAdapter As New OleDbDataAdapter(objCommand)
> >>         Dim objDataTabel As New Data.DataTable("Products")
> >>         Dim objDataRow As DataRow
> >>
> >>         objDataAdapter.Fill(objDataTabel)    '<----- Exception here
> >>
> >>
> >>         For Each objDataRow In objDataTabel.Rows
> >>             ListBox1.Items.Add(objDataRow.Item("Description") & " " &
> >> _
> >>                 objDataRow.Item("Size"))
> >>         Next
> >>
> >>     End Sub
> >> End Class
> >>
>
>
Author
17 Jan 2006 4:30 PM
Joyce
On Mon, 16 Jan 2006 18:28:01 -0800, "Kerry Moorman"
<KerryMoor***@discussions.microsoft.com> wrote:

Kerry! That was it!

I square-bracketted [Size] and it worked!!!!!!

Thank you SO much.

--Joyce

Show quoteHide quote
>Joyce,
>
>I was wrong about the dataadapter's Fill method requiring a dataset. It will
>also take a datatable, as you are doing in your code.
>
>I don't see anything obviously wrong with your code. I wonder if either
>Description or Size may be reserved words and need to be enclosed in square
>brackets in your Select statement:  Select [Description], [Size] From ...
>
>Kerry Moorman
>
Author
17 Jan 2006 7:32 AM
Cor Ligthert [MVP]
Joyce,

Your code is not the nicest, I would at least remove the code in that load
event completely.

However to see the error you can put first this in your code.
>        Dim objDataRow As DataRow
>
Try
>        objDataAdapter.Fill(objDataTabel)    '<----- Exception here

Catch ex as Exception

        messagebox.show(ex.toString)
End Try


Just to find what the error really is.

Cor