C# 数据库应用

来源:百度知道 编辑:UC知道 时间:2024/06/25 00:29:34
有两个Textbox 控件分别为 用户名和密码,如何将其与SQL中的用户表联系,判断Textbox中输入的SQL表中是否存在,

(1)你想自动实现吗?这样肯定是可以的,但灵活性太差。参考msdn.的“aspnet数据显示”
(2)写一个sql语句判断,select count(*) from users where name="" and pass="",返回0,就说明没有。

没有自动连的,要自己连去database

string name=string.format(select count(*) from users where name="{0}" ,Textbox)//前面用这个占位符,占位符的就是Textbox;
int n=sqlCommand.Exscla...
if(n>0)说明Textbox里的数值在数据库里存在

写个SQL语句啊,
select * from table where username=@username,password=@password
判断一下啊

select UserId from tb UserName = txtName.Text and UserPwd = txtPwd.Text
执行此语句判断用户名与密码是否在数据库中的表中存在

在textbox_changed 事件里
try

{select UserId from tb UserName = txtName.Text and UserPwd = txtPwd.Text
}
catch
{
}