mysqlCommand 方法
public static string connstr = "User Id=root;pwd= ;Host=localhost;Port=3306;Database=textbooks;Character Set=utf8";
MysqlConnection conn=MysqlConnection(connstr);
MysqlCommand command=new MysqlCommand(sql,conn);
ExecuteScalar: command.ExecuteScalar();返回object,是否有数据
ExecuteReader: command.ExecuteReader();返回MySqlDataReader类型mySqlRdr对象;
获取值
while (mySqlRdr.Read())
{
Console.WriteLine(mySqlRdr.GetString(0));
}
MySqlDataAdapter查询方法
MySqlDataAdapter adr=new MySqlDataAdapter(sql,conn);//不用command
DataSet T = new DataSet();
adr.Fill(T,"table1");
//this.dataGridView1.DataSource = ds.Tables["table1"];
DataTableReader dtr = T.CreateDataReader();
while (dtr.Read())
{
Console.WriteLine(dtr[0] + "###" + dtr.GetValue(1));
}