By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,334 Members | 1,388 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,334 IT Pros & Developers. It's quick & easy.

VISUAL C# and SQL

P: n/a
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[i]
[0].ToString();
}

it doesnt work what I should do?? how to set combo?? Do you have
better ideas??

Jan 27 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a
this should help:

http://www.codeproject.com/cs/miscct...mbersample.asp

(use combobox.items.add(object)...you'll see in above link)
"_nabuchodonozor" <kk******@wsb-nlu.edu.plwrote in message
news:11*********************@l53g2000cwa.googlegro ups.com...
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[i]
[0].ToString();
}

it doesnt work what I should do?? how to set combo?? Do you have
better ideas??

Jan 28 '07 #2

P: n/a
Thanks a lot this is excactly what I need:)

Jan 28 '07 #3

P: n/a

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


"_nabuchodonozor" <kk******@wsb-nlu.edu.plwrote in message
news:11**********************@v33g2000cwv.googlegr oups.com...
Thanks a lot this is excactly what I need:)

Jan 29 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.