如何判断变量和数据库中是否一致

来源:百度知道 编辑:UC知道 时间:2024/05/04 13:47:04
我用一个例子说吧,就是登陆界面,判断用户输入的和数据库中的是否一致,这么判断,两个都需要判断,C#语句这么写,谢谢~~~
请将SQL查询语句写出来~~~
2楼说的确实很详细,但是我运行时提示说>不能用于string 和int 操作数~~,帮我想想,我是菜鸟,谢谢!!!
3楼你也说说该这么改啊~~帮帮我~please!

string strTemp = "XXX"(此处XXX为你页面输入的值)

sql语句如下

select 1 from table where 数据库字段 = '"& strTemp &"';
此时得到一个数据集,如果数据集里面的个数大于0表示存在重复字段
或者
sleect count(1) from table where 数据库字段 = '"& strTemp &"';
此时得到的值如果大于0表示有重复字段

查询数据库.
select count(*) from table where 数据库字段1='输入内容1' and 数据库字段2='输入内容2'

你还指望他来搞防注入啊

//sql语句字符串
string sqlStr="select * from Table where uid='"+this.textBox1.text+"' and pwd='"+this.textBox2.text+"'";
//如果有返回说明登陆成功

SqlConnecttion con=new SqlConnecttion("server=.;database=数据库;uid=sa;pwd=");
string sql=select count(*) from 表where 数据库字段1='输入内容1' and 数据库字段2='输入内容2';

sqlCommand cmd=new sqlCommand(sql,con);
Object o=cmd.ExecuteSclar();
if (Convert.ToInt32(o)>0)
{
存在该用户.登陆
}
else
{
不存在该用户.
}