asp.net (C#), 如何实现简单的用户登录呀?请教了!!!

唉,请大家帮帮忙呀

用SqlDataSource控件绑定了数据源之后,如何验证输入TextBox的内容是否与数据库中的用户名和密码匹配呀?

谢谢啦!!
这是设置完数据源之后的代码:
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:OADBConnectionString %>"
SelectCommand="SELECT [Staff_Name], [Password] FROM [Staff] WHERE (([Staff_Name] = @Staff_Name) AND ([Password] = @Password))">

兄台你不应该这么做啊
既然你使用了SqlDataSource,那你一定是用的vs2005啦,可以用登录控件啊,Login控件,不用写任何代码就可以实现
如果您不想用,也可以自己写,放两个文本框,一个用户名,一个密码,点击登录按钮后在数据库验证就可以了
具体代码不用我写了吧?
还是写一下吧
SQL语句:select count(*) from 你的用户表 where username='文本框中的用户名' and password='文本框中的密码'
然后用ExcuteScraler()方法返回结果,如果为0,登录失败,否则成功
温馨提示:内容为网友见解,仅供参考
第1个回答  2007-11-03
直接给你个
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Text.RegularExpressions;
using system.data.Sqlclient;
namespace WindowsApplication2
{
private void button1_Click(object sender, EventArgs e)
{

if (user.Text.ToString() == "" || pwd.Text.ToString() == "")
{
MessageBox.Show("用户名或密码不能为空!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
sqlconnection con=new sqlConnection("server=.;database=login;uid=sa;pwd=;");
sqlcommand com=new Sqlcommand("select count(*) from login where username='"+user.text.tostring()+"' and userpwd='"+pwd.text.tostring()+"'",con):

con.open();
if com.excutescarl>0 then
Response.redirect(k.aspx)
else
massagebox("没有该记录");
相似回答