Re: Populating a dropdown listbox problem!
Chris Anderson <[email protected]> Wed, 19 Jun 2002 12:55:45 +0100
| Newsgroups | gmane.comp.windows.devel.dotnet.general |
|---|---|
| Message-ID | <316FA43F497FD411AD4000A0CC53D8123504D6@NOVASVR1> |
OleDbDataReader's return objects not strings You need to explicitly cast to a string, ie something like : (C++ is not my language of choice, so please ignore syntax errors) *sEmployClass = (string) objDataReader["employee_class_name"]; Merak > -----Original Message----- > From: dmlegare [mailto:[email protected]] > Sent: 19 June 2002 12:00 > To: [email protected] > Subject: [DOTNET] Populating a dropdown listbox problem! > > > How do I use my datareader object to populate a > dropdownlistbox??? Im getting conversion type errors..?????? > here is the code > > string myConnection = "........"; > string mySelectQuery = "select employee_class_name from > onlinetime_empclass "; OleDbConnection myConn = new > OleDbConnection(myConnection); OleDbCommand objCommand = new > OleDbCommand(mySelectQuery, myConn); OleDbDataReader > objDataReader = null; myConn.Open(); objDataReader = > objCommand.ExecuteReader(); string sEmployClass = ""; while > (objDataReader.Read() == true) > { > *sEmployClass = objDataReader["employee_class_name"]; > ddemployeeClassification.Items.Add(sEmployClass); > } > I get an error when i try to view in a browsers: > > *Compiler Error Message: CS0029: Cannot implicitly convert > type 'object' to 'string' > > You can read messages from the DOTNET archive, unsubscribe > from DOTNET, or subscribe to other DevelopMentor lists at > http://discuss.develop.com. > You can read messages from the DOTNET archive, unsubscribe from DOTNET, or subscribe to other DevelopMentor lists at http://discuss.develop.com.