VISUAL C# and SQL

  • Thread starter Thread starter _nabuchodonozor
  • Start date Start date
N

_nabuchodonozor

Hi,
I want to set value for combobox but without creators only code. I
want to set "titles" from tabel "films". I did something like this:

int limit=0; // how
many films I have in table
string qry = "select Title from films";
SqlDataAdapter dataAdapter = new SqlDataAdapter(qry,
conNW);
SqlCommand cmdFilm = new SqlCommand(qry, conNW);
conNW.Open();
limit = cmdFilm.ExecuteNonQuery(); // get number of films
conNW.Close();
SqlCommandBuilder commandBuilder = new
SqlCommandBuilder(dataAdapter);
DataTable table = new DataTable();
table.Locale =
System.Globalization.CultureInfo.InvariantCulture;
dataAdapter.Fill(table);
for (int i = 0; i < limit; i++) // set value for combo
{
comboBoxWybFilm.ValueMember = table.Rows
[0].ToString();
}

it doesnt work what I should do?? how to set combo?? Do you have
better ideas??
 
The thing that is lost in the sample is that you are

Putting OBJECTS into the combo box. Not just value/text pairs.

The author has create a little wrapper object to encapsulate a value/text
pair.
Which he populates with his IDataReader

Its a nice sample, just try to realize what is happening there, so you don't
just copy/paste in the future when you don't have to.

...

If you create a custom object

public class Employee
private string m_lastname;
private string m_firstname;
private string m_empid ;

public string EmpID
{ get { return this.m_empid ; }}
public override ToString()
{
return this.m_lastname +", " + this.m_firstname;
}

you have some control with properties .. or overriding the ToString()
 
Back
Top