all groups > vb.net > january 2006 >
vb.net :
Problem with DataAdapter Fill method, Ithink
Joyce, The dataadapter's Fill method requires a dataset as the argument, not a datatable. Kerry Moorman [quoted text, click to view] "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
[quoted text, click to view] 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...
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" 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" > <KerryMoorman@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 > >> >
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
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] wrote: > >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
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] <KerryMoorman@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 >>
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] > 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
On Mon, 16 Jan 2006 18:28:01 -0800, "Kerry Moorman" [quoted text, click to view] <KerryMoorman@discussions.microsoft.com> wrote:
Kerry! That was it! I square-bracketted [Size] and it worked!!!!!! Thank you SO much. --Joyce [quoted text, click to view] >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 >
Don't see what you're looking for? Try a search.
|
|
|