binding combobox
From: Edward (Edward_at_discussions.microsoft.com)
Date: 09/21/04
- Next message: aualias: "Re: DataRelations and DataGrids"
- Previous message: Stoitcho Goutsev \(100\) [C# MVP]: "Re: Question on Component"
- Next in thread: Claes Bergefall: "Re: binding combobox"
- Reply: Claes Bergefall: "Re: binding combobox"
- Messages sorted by: [ date ] [ thread ]
Date: Tue, 21 Sep 2004 06:29:05 -0700
Hello,
I'm sure a lot of you can help...
I have the following function:
****************
string sSQL = "SELECT CountryId, Country FROM Countries ORDER BY Country";
string sConnectionString = "SERVER=FGMCSQL;DATABASE=Web;USER
ID=sql123;PASSWORD=qwerty;";
SqlConnection sqlCon = new SqlConnection(sConnectionString);
sqlCon.Open();
SqlCommand sqlCom = new SqlCommand();
sqlCom.CommandType = CommandType.Text;
sqlCom.CommandText = sSQL;
sqlCom.Connection = sqlCon;
SqlDataAdapter da = new SqlDataAdapter(sqlCom);
DataTable dt = new DataTable();
da.Fill(dt);
cboDTCountry.DataSource = dt.DefaultView;
cboDTCountry.ValueMember = "CountryId";
cboDTCountry.DisplayMember = "Country";
sqlCon.Close();
***********
Can anyone tell me why I'm getting an error when my sql string is changed to:
string sSQL = "SELECT * FROM Countries ORDER BY Country";
The error happens in this line:
cboDTCountry.ValueMember = "CountryId";
It says it cannot bind to it. I know asp.net doesn't generate this error
when this same concept is applied. Can anyone explain why using an asterisk
(*) generates this error? Must I instead select individual fields from the
database? While your reading this, I'm very open to any suggestions on
improving this simple function. Please have a shot at it!
Thanks,
Edward
- Next message: aualias: "Re: DataRelations and DataGrids"
- Previous message: Stoitcho Goutsev \(100\) [C# MVP]: "Re: Question on Component"
- Next in thread: Claes Bergefall: "Re: binding combobox"
- Reply: Claes Bergefall: "Re: binding combobox"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|