p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   VB Databases Basics (http://p2p.wrox.com/forumdisplay.php?f=82)
-   -   List Box to populate DataGridView (http://p2p.wrox.com/showthread.php?t=87876)

03224 June 28th, 2012 09:04 PM

List Box to populate DataGridView
 
I have this windows form, just LISTBOX and DATAGRIDVIEW
i want to dispaly information about an item select in the listbox
i can populate the listbox just fine, but nothig is display on the datagridview when i click on a name
here is my code:
Code:

Private Sub Status_Load(sender As Object, e As System.EventArgs) Handles Me.Load
        'TODO: This line of code loads data into the 'ReturnEquipmentDataSet.RMA' table. You can move, or remove it, as needed.

        Dim con As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Database\ReturnEquipment.accdb;Persist Security Info=False;")

        Dim CMD1 As New OleDb.OleDbCommand
        CMD1.Connection = con

        con.Open()

        CMD1.CommandText = "SELECT SN from RMA"
        Dim miDataReader As OleDb.OleDbDataReader
        miDataReader = CMD1.ExecuteReader
        Dim dt As New DataTable
        dt.Load(miDataReader)
        LbxSerial.DataSource = dt
        LbxSerial.ValueMember = dt.Columns(0).ToString()
        LbxSerial.DisplayMember = dt.Columns(0).ToString()
        miDataReader.Close()
        con.Close()

    End Sub



    Private Sub LbxSerial_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles LbxSerial.SelectedIndexChanged
        Dim con As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Database\ReturnEquipment.accdb;Persist Security Info=False;")
        Dim cmd As New OleDbCommand("Select * from( rma) where sn = @SN Order by Rma_Number")
        cmd.Parameters.AddWithValue("@SN", Me.LbxSerial.SelectedItem.ToString)
        cmd.Connection = con

        con.Open()
        Dim da As OleDbDataAdapter = New OleDbDataAdapter
        Dim ds As DataSet = New DataSet
        da.SelectCommand = cmd
        da.Fill(ds)

        DataGridView1.DataSource = ds


    End Sub
End Class

When i run this application no error , but no info is dispaly
what am I doing wrong?


All times are GMT -4. The time now is 12:27 AM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.