如何在c#中执行mySql命令

时间:2017-03-23 15:06:24

标签: c# mysql asp.net .net

我有以下MySql命令

MySqlCommand binData = new MySqlCommand("SELECT binType, binColour from bin WHERE '"
                        + sessionVarAddress +"' = address_addressID ", connect);

我想尝试执行此操作,并尝试如下:

foreach(DataRow in binData.ExecuteReader())

但这是不正确的,我该如何正确执行此命令?

1 个答案:

答案 0 :(得分:1)

你可以执行它:

var reader = binData.ExecuteReader();
while (reader.Read())
{
     // do whatever you need, access reader data as reader[i]
}
reader.Close();

有关详细信息,请参阅MySQL documentation