Richard1996 Richard1996 -4 years ago 183
MySQL Question

How to execute mySql command in c#

I have the following MySql command

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

I want to try to execute this and I have tried as follows:

foreach(DataRow in binData.ExecuteReader())

but this is incorrect, how can I properly execute this command?

Answer Source

You can execute it like:

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

See MySQL documentation for details.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download