Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > VB Databases Basics
| Search | Today's Posts | Mark Forums Read
VB Databases Basics Beginning-level VB coding questions specific to using VB with databases. Issues not specific to database use will be redirected to other forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB Databases Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 28th, 2012, 09:04 PM
Registered User
Points: 5, Level: 1
Points: 5, Level: 1 Points: 5, Level: 1 Points: 5, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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?




Similar Threads
Thread Thread Starter Forum Replies Last Post
Populate a text box from a combo box value dnf999 Access VBA 7 February 6th, 2012 02:24 PM
Populate a list box from comma separated values CoderNH Access VBA 3 October 20th, 2008 08:37 AM
Populate a List Box with Table Names & Table date hewstone999 Access VBA 1 February 27th, 2008 10:10 AM
multi-column list box values moved to 2nd list box sbmvr Access VBA 1 May 14th, 2007 01:58 PM
Populate List Box by Combo Box Selection mmcdonal Access 2 June 15th, 2004 12:08 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.