string con = "server=127.0.0.1;user id=root;password=;database=db";MySqlConnection sqlconn = new MySqlConnection(con);sqlconn.Open();string sql = "select * from users where NAME=?NAME;";MySqlCommand cmd=new MySqlCommand (sql,sqlconn);cmd.Parameters.Add("?NAME", MySqlDbType.VarChar).Value ="张山"; MySqlDataAdapter myda = new MySqlDataAdapter(cmd);DataTable dt = new DataTable();myda.Fill(dt);myda.Dispose();sqlconn.Dispose();sqlconn.Close();dataGridView1.DataSource = dt;users表ID bigintname varchar(500);
2 回答
米脂
TA贡献1836条经验 获得超3个赞
string con = "server=127.0.0.1;user id=root;password=;database=db";
password= 后面啥都没有
string sql = "select * from users where NAME=?NAME;";
改成string sql = "select *,@NAME from users";不是什么条件,我晕
cmd.Parameters.Add("@NAME", MySqlDbType.VarChar).Value ="张山";就好了,不是Oracle
慕少森
TA贡献2019条经验 获得超9个赞
string
sql =
"select * from users where NAME=?NAME;"
;改为
string
sql =
"select * from users where NAME=@NAME"
;
cmd.Parameters.Add(
"?NAME"
, MySqlDbType.VarChar).Value =
"张山"
;
改为:
cmd.Parameters.Add(
"@NAME"
, MySqlDbType.VarChar).Value =
"张山"
;
添加回答
举报
0/150
提交
取消