C#, MySQL,运行SQL语句,并按行顺序处理数据:
MySqlConnection mysql = new MySqlConnection(ConfigurationSettings.AppSettings["Connection"]);
mysql.Open();
MySqlCommand cmd = mysql.CreateCommand();
cmd.CommandText = "sql语句";
MySqlDataReader rdr = cmd.ExecuteReader();
while (rdr.Read()) {
}
读取到DataTable并遍历:
MySqlConnection mysql = new MySqlConnection(ConfigurationSettings.AppSettings["Connection"]);
mysql.Open();
String sql = @"SELECT devID, device_id, devName, deviceName, lng, lat FROM tb_device A, devinfo b WHERE a.`id` = b.`device_id`";
MySqlDataAdapter msa = new MySqlDataAdapter(sql, mysql);
DataTable dt = new DataTable();
msa.Fill(dt);
foreach (DataRow rdr in dt.Rows)
{
}