Click here to Skip to main content
12,894,249 members (71,657 online)
Rate this:
Please Sign up or sign in to vote.
See more: C#
I am using MS Access Database.

Design in MSAccess as follows;

Faculty_Name Text

My Code as follows in Load button;

when i click the Load button faculty_Name to be retrieved from the DB and displayed in the List box.

string connstring = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source= E:\\Projects\\Faculty Schedule\\Faculty Schedule\\Data\\HIMTTESTing.mdb;";
OleDbConnection OleDbCon = new OleDbConnection(connstring);
string sql1 = "select Faculty_Name from  Tb_SCH_Faculty_Details ";
OleDbCommand cmd = new OleDbCommand(sql1, OleDbCon);
OleDbDataReader reader = cmd.ExecuteReader();

when i run in the List box the Faculty_Name is not displaying.

from my above code what is the can i do.please help me.

[Edit]Code block added by Jibesh[/Edit]
Posted 23-Jan-13 21:26pm
Updated 23-Jan-13 21:51pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

you have to add one by one records
while (reader.Read())
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

you have to use loop statement to read the reader and add data to listbox i.e

while (reader.Read())

where reader.GetString()
get the row with all colums as given 'reader.GetString(0)' gets the first colum value of the current row

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170424.1 | Last Updated 24 Jan 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100