在winform里,如果where后面的abc是变量的话,应该怎么改写?
在winform里,如果where后面的abc是变量的话,应该怎么改写?SqlCommand cmd = new SqlCommand("delete from QQqun1 where LEI=a and shouji=b,ZID=c "); --------------------编程问答-------------------- SqlCommand cmd = new SqlCommand("delete from QQqun1 where LEI=" + a + " and shouji=" + b + " and ZID=" + c);
如果abc是字符串,还要加上引号
SqlCommand cmd = new SqlCommand("delete from QQqun1 where LEI='" + a + "' and shouji='" + b + "' and ZID='" + c + "'"); --------------------编程问答--------------------
--------------------编程问答-------------------- 最好用参数传递变量值,象不同电脑日期格式可能不一样,直接传值有可能查询一台服务器上正常,换台服务器就查询错误了 --------------------编程问答-------------------- 变量不是字符串时采用:
SqlCommand cmd = new SqlCommand("delete from QQqun1 where LEI=@a and shouji=@b and ZID=@c ");
cmd.Parameters.Add("@a", SqlDbType.Int).Value = 111;
cmd.Parameters.Add("@b", SqlDbType.Date).Value = '2013-10-20';
cmd.Parameters.Add("@c", SqlDbType.NVarChar, 50).Value = 'aaaaaa';
SqlCommand cmd = new SqlCommand("delete from QQqun1 where LEI=" + a + " and shouji=" + b + " and ZID=" + c);
变量是字符串时采用:
SqlCommand cmd = new SqlCommand("delete from QQqun1 where LEI='" + a + "' and shouji='" + b + "' and ZID='" + c + "'");
--------------------编程问答--------------------
SqlCommand cmd = new SqlCommand((string.Format("delete from QQqun1 where LEI={0} and shouji={1},ZID={2} ",a,b,c)));--------------------编程问答-------------------- 如果你的事字符串,就把{0}改成'{0}' --------------------编程问答-------------------- 1楼正解....... --------------------编程问答-------------------- 加引号是对的,但注意不要加错了,而且要是英文的引号
补充:.NET技术 , C#