VISUAL C# and SQL

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??
 
S

sloan

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()
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top