Sunday, December 11, 2011

How to import items into a lisbox in vb.net?

I need help. I have the txt file from which I need to import a list of items into a listbox, but I can't get them to display. Can someone please help me with this? I'm using StreamReader. I just need the code to set it to display. Also, I can only display 10 items from the list at one time, how would I do this. Thank you so much!How to import items into a lisbox in vb.net?
Dim boolHeaderRow As Boolean = False

Dim strFileConnectionString As String = ';';

Dim FileDirectory, FileName As String

Dim Header As String = ';';



FileDirectory = ';REPLACE WITH YOUR FILE DIRECTORY LOCATION';

FileName = ';REPLACE WITH YOUR FILE NAME';

Header = ';REPLACE WITH YES OR NO. Does the file contain a header row?';



Dim ConnectionString, CommandText As String

Dim conn As OleDb.OleDbConnection

Dim Command As OleDb.OleDbCommand



ConnectionString = ';Provider=Microsoft.Jet.OLEDB.4.0;Data Source='; _

%26amp; FileDirectory %26amp; ';\;Extended Properties='text;HDR='; %26amp; Header %26amp; ';'';



CommandText = ';select TOP 10 * from '; %26amp; FileName



conn = New System.Data.OleDb.OleDbConnection _

(ConnectionString)



Command = New System.Data.OleDb.OleDbCommand _

(CommandText, conn)



conn.Open()



Dim da As OleDb.OleDbDataAdapter = New OleDb.OleDbDataAdapter _

(CommandText, conn)

Dim ds As DataSet = New DataSet



da.Fill(ds, ';Employees';)



Dim ListBox As New ListBox

'Change this to your listbox



With ListBox

.DataSource = ds

.DataTextField = ';F1';

.DataValueField = ';F2';

.DataBind()

End With



conn.Close()
  • kids myspace
  • affordable laptop repair
  • No comments:

    Post a Comment