Listbox and DataGrid
Listbox and DataGrid
Listbox and DataGrid
Listbox and DataGrid
Listbox and DataGrid
Listbox and DataGrid Listbox and DataGrid Listbox and DataGrid Listbox and DataGrid Listbox and DataGrid Listbox and DataGrid Listbox and DataGrid Listbox and DataGrid
Listbox and DataGrid Listbox and DataGrid
Listbox and DataGrid
Go Back  Xtreme Visual Basic Talk > > > Listbox and DataGrid


Reply
 
Thread Tools Display Modes
  #1  
Old 06-24-2012, 12:06 PM
03224 03224 is offline
Newcomer
 
Join Date: Jun 2012
Posts: 1
Default Listbox and DataGrid


I have this windows form one ListBox and a DataGrid.
what i want is to display in the datagrid the pertinet information of the selected value on the list box.
bellow is my code, this code populate the list view just fine, but faild to disply information about the employee i select on the listbox.
what i am doing wrong, any help>
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()

        'Load the grid view




    End Sub


    Sub Listchange(S As Object, e As EventArgs)
        Dim conn As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Database\ReturnEquipment.accdb;Persist Security Info=False;")

        Dim myCommand = New OleDbCommand("select * from RMA WHERE SN = LbxSerial.Selecteditem.value")
        myCommand.Connection = conn
        conn.Open()

        Dim ds As Data.DataSet = New Data.DataSet
        Dim dr As OleDbDataReader
        Dim DA As New OleDbDataAdapter
        DA.SelectCommand = myCommand
        dr = myCommand.ExecuteReader
        myCommand.Connection = conn
        DA.Fill(ds, "RMA")
        DataGridView1.DataSource = ds
        dr.Close()

        conn.Close()
    End Sub

Last edited by Flyguy; 06-25-2012 at 01:52 AM.
Reply With Quote
  #2  
Old 06-25-2012, 06:49 PM
mmcginty mmcginty is offline
Newcomer
 
Join Date: Apr 2009
Location: Central California Coast
Posts: 13
Default

If you set DataSource to a DataSet, you also need to set DataMember. Instead, pass a DataTable to DA.Fill, and use that as DataSource.

btw, the DataReader is superflous in the routine Listchange. For one thing you're calling ExecuteReader before setting the command's connection -- which by rights ought to throw an error... OIC, you assign the connection twice... Anyway, Fill reads the data for you, so the lines that declare and reference dr only add overhead without adding functionality.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Listbox and DataGrid
Listbox and DataGrid
Listbox and DataGrid Listbox and DataGrid
Listbox and DataGrid
Listbox and DataGrid
Listbox and DataGrid Listbox and DataGrid Listbox and DataGrid Listbox and DataGrid Listbox and DataGrid Listbox and DataGrid Listbox and DataGrid
Listbox and DataGrid
Listbox and DataGrid
 
Listbox and DataGrid
Listbox and DataGrid
 
-->