有关mysql参数化查询的问题
代码如下string constr = "User Id=root;Host=localhost;Database=discoverxdb;password=123";
string strsql,strsql2;
string str1 = Request["unid"];
MySqlConnection myconn = new MySqlConnection(constr);
//HttpCookie cookie = Request.Cookies ["unid"];
//String cookieunid = Request.Cookies["unid"].ToString();
strsql="select cust_id,cust_name from vt_frmcust where punid=@str1";
//id="+Request.QueryString["nid"]
strsql2="select * from vt_frmproject order by proj_id ";
myconn.Open();
MySqlCommand mycm = new MySqlCommand(strsql,myconn);
MySqlDataReader msdr = mycm.ExecuteReader();
while(msdr.Read())
{
if (msdr.HasRows)
{
//Console.WriteLine(msdr.GetString(0));
TextBox1.Text=msdr.GetString(0);
TextBox2.Text=msdr.GetString(1);
}
}
msdr.Close();
但是查询不到结果
写的有什么错误吗?
c#要参数化查询怎么写?
望高手解答 --------------------编程问答-------------------- strsql="select cust_id,cust_name from vt_frmcust where punid=@str1";
跟一下这个语句在MYSQL中能否查询出数据 --------------------编程问答-------------------- 可以查出
SELECT * FROM vt_frmcust v where punid='E0B7C94BB4444B9BA99666F9025C7A11'
查的的结果
'E0B7C94BB4444B9BA99666F9025C7A11', '00001,0003' --------------------编程问答-------------------- 没人解答吗?
自己顶 --------------------编程问答-------------------- while(msdr.Read())
{
TextBox1.Text=msdr[0];
TextBox2.Text=msdr[1];
}
} --------------------编程问答-------------------- TextBox1.Text=msdr[0];
TextBox2.Text=msdr[1];
不行,编译不过去,无法将类型Object隐形转化成string,应该不是这个问题 --------------------编程问答-------------------- 我又加了两句
MySqlConnection myconn = new MySqlConnection(constr);
MySqlCommand mycomm =new MySqlCommand(constr);
strsql="select cust_id,cust_name from vt_frmcust where punid=@str1";
mycomm.Parameters.Add("@str1",MySqlDbType.VarChar,32);
mycomm.Parameters["@str1"].Value=Request["unid"];
还是不行
mysql参数要怎么写啊
急 --------------------编程问答-------------------- 自己顶 --------------------编程问答-------------------- MySqlConnection myconn = new MySqlConnection(constr);
MySqlCommand mycomm =new MySqlCommand(constr);
strsql= "select cust_id,cust_name from vt_frmcust where punid=?str1 ";
mycomm.Parameters.Add( "?str1 ",MySqlDbType.VarChar,32);
mycomm.Parameters[ "?str1 "].Value=Request[ "unid "];
把“@”改成“?”,即可 --------------------编程问答--------------------
把“@”改成“?”,即可
正解,我刚试过,多谢。
补充:.NET技术 , C#