Groups | Blog | Home
all groups > vb.net > january 2006 >

vb.net : Problem with DataAdapter Fill method, Ithink


Kerry Moorman
1/16/2006 3:10:02 PM
Joyce,

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

Kerry Moorman


[quoted text, click to view]
I Don't Like Spam
1/16/2006 6:04:54 PM

[quoted text, click to view]

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

Kerry Moorman
1/16/2006 6:28:01 PM
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


[quoted text, click to view]
Joyce
1/16/2006 10:24:31 PM

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
Joyce
1/16/2006 11:30:42 PM
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>
[quoted text, click to view]
Joyce
1/16/2006 11:35:46 PM
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"
[quoted text, click to view]
Cor Ligthert [MVP]
1/17/2006 8:32:44 AM
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.
[quoted text, click to view]

Catch ex as Exception

messagebox.show(ex.toString)
End Try


Just to find what the error really is.

Cor

Joyce
1/17/2006 4:30:44 PM
On Mon, 16 Jan 2006 18:28:01 -0800, "Kerry Moorman"
[quoted text, click to view]

Kerry! That was it!

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

Thank you SO much.

--Joyce

[quoted text, click to view]
AddThis Social Bookmark Button