I'm trying to query an MySql table, put all results into a combobox.
So my query results in apple 2220
I want to populate the combobox with apple2220
i'm having trouble getting the string outside of datarow.
string MyConString = "SERVER=localhost;" +
"DATABASE=iie;" +
"UID=root;" +
"PASSWORD=xxxx;";
MySqlConnection connection = new MySqlConnection(MyConString);
string command = "select fruit,number from clientinformation";
MySqlDataAdapter da = new MySqlDataAdapter(command,connection);
DataTable dt = new DataTable();
da.Fill(dt);
foreach (DataRow row in dt.Rows)
{
string rowz = row.ItemArray.ToString();
}
connection.Close();
解决方案
Try something along these lines:
...
foreach (DataRow row in dt.Rows)
{
string rowz = string.Format("{0}:{1}", row.ItemArray[0], row.ItemArray[1]);
yourCombobox.Items.Add(rowz);
}
....