Re: datarowview
From: Hutty (Hutty_at_discussions.microsoft.com)
Date: 07/12/04
- Next message: Aaron [SQL Server MVP]: "Re: SQL Server 2005 Express Beta messes up your SQL Server 2000, BEWARE"
- Previous message: Alvin Bruney [MVP]: "Re: SQL Server 2005 Express Beta messes up your SQL Server 2000, BEWARE"
- In reply to: John Saunders: "Re: datarowview"
- Next in thread: Hutty: "Re: datarowview"
- Reply: Hutty: "Re: datarowview"
- Messages sorted by: [ date ] [ thread ]
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 > > >
- Next message: Aaron [SQL Server MVP]: "Re: SQL Server 2005 Express Beta messes up your SQL Server 2000, BEWARE"
- Previous message: Alvin Bruney [MVP]: "Re: SQL Server 2005 Express Beta messes up your SQL Server 2000, BEWARE"
- In reply to: John Saunders: "Re: datarowview"
- Next in thread: Hutty: "Re: datarowview"
- Reply: Hutty: "Re: datarowview"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|