Click here to Skip to main content
15,886,799 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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.

C#
string connstring = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source= E:\\Projects\\Faculty Schedule\\Faculty Schedule\\Data\\HIMTTESTing.mdb;";

OleDbConnection OleDbCon = new OleDbConnection(connstring);
OleDbCon.Open();
string sql1 = "select Faculty_Name from  Tb_SCH_Faculty_Details ";
OleDbCommand cmd = new OleDbCommand(sql1, OleDbCon);
OleDbDataReader reader = cmd.ExecuteReader();
{
   Lb_Faculty_Name.Items.Add(reader);
}
OleDbCon.Close(); 

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

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

[Edit]Code block added by Jibesh[/Edit]
Posted
Updated 23-Jan-13 21:51pm
v2

you have to add one by one records
while (reader.Read())
{
Lb_Faculty_Name.Items.Add(reader[0].tostring());
}
 
Share this answer
 
you have to use loop statement to read the reader and add data to listbox i.e

while (reader.Read())
{
Lb_Faculty_Name.Items.Add(reader.GetString(0));
}


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

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900