Re: Populating a dropdown listbox problem!
dmlegare <[email protected]> Wed, 19 Jun 2002 12:05:08 -0400
| Newsgroups | gmane.comp.windows.devel.dotnet.general |
|---|---|
| Message-ID | <[email protected]> |
Interesting.. I took the example straight from the book!! It appears to be a flaw in code or I missed a line somewhere even though I know i doubled checked prior to sending the email.. Thanks for the response! ----- Original Message ----- From: "Wayne Lee" <[email protected]> To: <[email protected]> Sent: June 19, 2002 8:01 AM Subject: Re: [DOTNET] Populating a dropdown listbox problem! > Well it's because the add method requires a listitem object and not a > string...here > > If you're not using data binding and want a quick fix add this after the > first { in your while loop > > ListItem li = new ListItem(); > > li.Value = sEmployClass; > li.Text = sEmployClass; > > ddemployeeClassification.Items.Add(li); > > There's more that could be done, but this should fix your problem for > now! > > Wayne Lee > Evident Systems Ltd > This email has been scanned with Norton AntiVirus 2002 > > > -----Original Message----- > From: The DOTNET list will be retired 7/1/02 > [mailto:[email protected]] On Behalf Of dmlegare > 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. > You can read messages from the DOTNET archive, unsubscribe from DOTNET, or subscribe to other DevelopMentor lists at http://discuss.develop.com.