Telling Lst's to display imported data (simple)

bopo

Member
Joined
Dec 10, 2006
Messages
13
Programming Experience
Beginner
HI

Below is the coding, I have finally been able to extra data from a MS Acess database and make it display in text boxes, however I tried switching to list boxes and it totally doesnt work, below the code:

VB.NET:
Imports System.Data.OleDb
Public Class ProblemForm
Inherits System.Windows.Forms.Form
Dim cn As OleDbConnection
Dim cmd As OleDbCommand
Dim dr As OleDbDataReader
 
Private Sub ProblemForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
 
End Sub
 
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Try
cn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\Emp.mdb;")
cn.Open()
cmd = New OleDbCommand("select * from table1", cn)
dr = cmd.ExecuteReader
While dr.Read
lstproblemd.Text = dr(1) 'so how do I tell a list box to do this?
lsturgency.Text = dr(2)
'loading data
End While
Catch
End Try
dr.Close()
cn.Close()
 
End Sub
End Class
 
Last edited by a moderator:
May be should try out
VB.NET:
[SIZE=2][COLOR=#0000ff]me[/COLOR][/SIZE][SIZE=2].lstproblemd.Items.Add(dr(1))[/SIZE]
[SIZE=2]me[SIZE=2].lsturgency.Items.Add(dr(1))
[/SIZE][/SIZE]

or load the data to the dataset and bind it to the list box

VB.NET:
        Me.lstproblemd.DataSource = myDataSet.Tables("MyTable")
        Me.lstproblemd.DisplayMember = "SomeColToDisplay"
 
Hi

Thanks for that, I managed to figure it out anyway, however it is only importing 2 lines, any idea how to import everything?

Edit: I can import everything now, its a problem with another piece of coding, however It wont let me import numbers, it just comes up with an error
 
Read the DW2 link in my signature - youre doing things the hard way which, great, it gives you an understanding of what goes on underneath, but its very tedious and in relative historic terms, it's a dinosaur that suffers from all manner of OO-priciple violating maladies
 
Back
Top