darrennelson
asked on
DB Query to populate dropdown C#
I've got a function that grabs a list of storeID's to populate a dropdown. I'd like to change the sql statement to grab both storeID and storeName so that the contents of the drop down show the storeName appended to the storeID. If I change the sql statement to read:
select storeid,storename from storemaster where...
what do I need to do to put both values into "storeID"?
select storeid,storename from storemaster where...
what do I need to do to put both values into "storeID"?
public static List<string> GetStoresCO()
{
List<string> oStores = new List<string>();
string sql = "select storeid from storemaster where StoreType = 'CO' and StoreOpen = 1 order by storeid";
string conString = ConnectStringDB.connectionString;
System.Data.SqlClient.SqlConnection myConnection = new System.Data.SqlClient.SqlConnection(conString);
System.Data.SqlClient.SqlCommand myCommand = new System.Data.SqlClient.SqlCommand(sql, myConnection);
System.Data.SqlClient.SqlDataReader myReader;
try
{
myConnection.Open();
myReader = myCommand.ExecuteReader();
while (myReader.Read())
{
string store = myReader["storeid"].ToString();
oStores.Add(store);
}
myConnection.Close();
}
catch (System.Exception ex)
{
string st = ex.Message;
}
return oStores;
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
no need to cast...thanks
SELECT CAST(storeid AS varchar(10)) + ' ' + storename AS storeid