Re: datarowview

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Hutty (Hutty_at_discussions.microsoft.com)
Date: 07/12/04


Date: Sun, 11 Jul 2004 18:21:03 -0700

Thanks John. I had tried selectedvalue before as well. I even have a textbox that displays the selected item from the listbox and tried substituting it in the query. I get an error on the Mycommand.Fill(DS1) in the following code. The error is:

An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred in system.data.dll

The code is:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim DS1 As System.Data.DataSet
        Dim DT As System.Data.DataTable
        Dim MyCommand As System.Data.OleDb.OleDbDataAdapter
        Dim MyConnection As System.Data.OleDb.OleDbConnection
        
        Dim Cat As String
        Cat = ListBox1.SelectedValue
        MsgBox(Cat)

        MyConnection = New System.Data.OleDb.OleDbConnection( _
         "provider=Microsoft.Jet.OLEDB.4.0; " & _
         "data source=C:\Inetpub\wwwroot\intelis.MDB")

        MyCommand = New System.Data.OleDb.OleDbDataAdapter( _
              "select * from '" & ListBox1.SelectedValue.ToString & "' where Entity = '" & ComboBox1.Text.Trim & "'", MyConnection)

        DS1 = New System.Data.DataSet
        DS1.Clear()

        MyCommand.Fill(DS1)

        DT = DS1.Tables(0)
        ' DataGrid1.DataMember =
        DataGrid1.DataSource = DT

        ' Dim form2 As New Form2
        'form2.Show()

        ' MyConnection.Close()
    End Sub

-- 
Hutty
"John Saunders" wrote:
> "Hutty" <Hutty@discussions.microsoft.com> wrote in message
> news:69FC7E6E-D3C9-460F-8E07-512DC3031AE1@microsoft.com...
> > I have a listbox that pulls data from an access database through the
> OLEDBDataAdapter.  In the same project I have OLEDBDataAdapter Command using
> SQL that's referencing the selected item in the listbox.  I get an error in
> "Fill" command.  The reason being I think is that I'm trying to convert a
> datarowview to a string in my SQL.  Here's the SQL.
> >
> > "select * from  '" & ListBox1.SelectedItem.ToString & "'  where Entity =
> '" & ComboBox1.Text.Trim & "'", MyConnection)
> >
> > The oddity of it all is that the "ComboBox1.Text.Trim" has a similar
> relationship where it's being filled through an OLEDBDataAdapter.  The SQL
> substitutes combobox1.text into query.
> 
> ListBox1.SelectedItem will be a DataRowView when you have bound the listbox
> to a data source. You don't want SelectedItem at all. You want
> ListBox1.SelectedValue instead.
> 
> -- 
> John Saunders
> johnwsaundersiii at hotmail
> 
> 
> 


Relevant Pages

  • Re: datarowview
    ... Here's the correct SQL for future reference. ... > Thanks John. ... I had tried selectedvalue before as well. ... I even have a textbox that displays the selected item from the listbox and tried substituting it in the query. ...
    (microsoft.public.dotnet.framework)
  • Re: datarowview
    ... single quotes surrounding the reference to the listbox. ... SQL for future reference. ... John Saunders ... I had tried selectedvalue before as well. ...
    (microsoft.public.dotnet.framework)
  • Re: Yes/No Display
    ... Thank you John. ... You can use the format function in the query that is the source for the list box. ... After you modify the source you should then see Yes or No in the listbox for ... "Golfinray" wrote: ...
    (microsoft.public.access.gettingstarted)
  • Re: sending data to multiple people
    ... I have a listbox with Arvin, John, Mary, Daisy ... I click John, ... Arvin Meyer wrote: ...
    (microsoft.public.access.formscoding)
  • Re: adding items to listbox with extra data similar to databinding to dataview
    ... right listbox, then, we may remove the selected item from the left listbox. ... For your first post issue, I am not sure I understand you well. ... ListBox's value and display member concept only make sense for databinding ... SelectedValue property of ListBox to retrieve the associated ID value of ...
    (microsoft.public.dotnet.framework.windowsforms)