HI,
I'm trying to connect to a db using ADO.NET in C#, but it generate
error.. I want to display in a combobox the values of one of the field.
(department name)
I'm new in C#, so I don't know what happen to the code below:
OleDbConnection objConnection = new
OleDbConnection ("Provider=Micr osoft.Jet.OLEDB .4.0; Data
Source=D:\\db1. mdb");
OleDbCommand myCommand = new OleDbCommand("s elect DEPT_NAME from
DEPT__2004 order by DEPT_NAME", objConnection);
try
{
objConnection.O pen();
OleDbDataReader objReader = myCommand.Execu teReader();
// fill ComboBox with department name
while ( objReader.Read( ) )
{
comboBox2.Items .Add(
objReader[ "DEPT_NAME" ] );
}
objConnection.C lose(); // close database connection
}
catch (Exception ex)
{
MessageBox.Show ("Failed");
}
finally
{
objConnection.C lose();
}
Cheers!
Claudi
*** Sent via Developersdex http://www.developersdex.com ***
Comment