| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1609 人关注过本帖
标题:求C#的登陆程序,连SQL2000的哪位高手能帮帮我,我是新手。
只看楼主 加入收藏
大宋提刑官
Rank: 1
等 级:新手上路
帖 子:25
专家分:0
注 册:2006-7-8
收藏
 问题点数:0 回复次数:15 
求C#的登陆程序,连SQL2000的哪位高手能帮帮我,我是新手。
C#的登陆程序,连SQL2000的哪位高手能帮帮我,我是新手。
搜索更多相关主题的帖子: 登陆 
2007-03-28 20:30
天使不哭
Rank: 6Rank: 6
等 级:贵宾
威 望:23
帖 子:677
专家分:22
注 册:2006-7-9
收藏
得分:0 

如果你能将你的问题描述清除一点的话,我想会有人愿意帮助你~~


C#Winform技术群:25380362
博客:http:///boyliupan/
2007-03-28 21:31
magic_ln
Rank: 1
等 级:新手上路
帖 子:71
专家分:0
注 册:2005-12-20
收藏
得分:0 

下一个例子看看,论坛上蛮多地。


当你对自己满意时,那便是退步的开始!    
2007-03-28 21:32
叶子521
Rank: 1
等 级:新手上路
帖 子:19
专家分:0
注 册:2007-3-8
收藏
得分:0 
用DataReader
读取你的输入和数据库的数据比较吧
论坛里面有例子,你也可以找找看的

2007-03-28 22:51
大宋提刑官
Rank: 1
等 级:新手上路
帖 子:25
专家分:0
注 册:2006-7-8
收藏
得分:0 

问题解决了,谢谢大家的支持。

2007-04-03 18:39
zhjesse
Rank: 1
来 自:西藏拉萨
等 级:新手上路
帖 子:205
专家分:0
注 册:2007-4-3
收藏
得分:0 

面是我最近几天刚弄好的代码,它能够判断 是否输入了用户名和密码 以及 输入的是否真确!!

当然还能加入“连续登录错误 N 次 系统自动关闭”以及其他的一些功能,谁想加入的可以互相讨论啊

现在共享一下:


private void button1_Click(object sender, EventArgs e)//button1的Text是:登录
{

if (this.textBox1.Text == "")
{
MessageBox.Show("用户名不能为空!", "错误");
}
else if (this.textBox2.Text == "")
{
MessageBox.Show("密码不能为空!", "错误");
}
else
{
if (IsUser(this.textBox1.Text))
{
if (this.textBox2.Text == LoginUser(this.textBox1.Text))
{
Form2 frm2 = new Form2();
// //frm2.showdialog();
frm2.Show();
Close();
}
else
{
MessageBox.Show("密码错误!");
}
}
else
{
MessageBox.Show("用户名错误!");
}
}


}


private string LoginUser(string uName) //检测用户是否能够登录
{
DataSet ds = new DataSet();

string u = uName;
OleDbConnection conn = new OleDbConnection("Data Source=F:\\c#.net\\学生信息管理\\denglu.mdb;provider=Microsoft.Jet.OLEDB.4.0");//连接数据库,我用的是Access
OleDbDataAdapter daAuthors = new OleDbDataAdapter("Select * From denglubiao where userName='" + uName + "'", conn);
conn.Open();
daAuthors.Fill(ds, "denglubiao");

return ds.Tables[0].Rows[0]["userPassWD"].ToString();
//SqlParameter parName = new SqlParameter("@Name", SqlDbType.VarChar, 50);
// parName.Value = User;
OleDbParameter parName = new OleDbParameter("@Name", OleDbType.VarChar, 50);
conn.Close();
}


private bool IsUser(string uName) //检测用户输入的用户名是否存在
{
DataSet ds = new DataSet();

OleDbConnection conn = new OleDbConnection("Data Source=F:\\c#.net\\学生信息管理\\denglu.mdb;provider=Microsoft.Jet.OLEDB.4.0");//连接数据库
OleDbDataAdapter daAuthors = new OleDbDataAdapter("Select userPassWD From denglubiao where userName='" + uName + "'", conn);
conn.Open();
daAuthors.Fill(ds, "denglubiao");

int n;
n = ds.Tables[0].Rows.Count;
if (n > 0)
return true;//存在就返回true
else
return false;

conn.Close();
}

private void button2_Click(object sender, EventArgs e)//button2的 Text属性是:取消登录
{
Application.Exit();//用户取消登录,退出系统
}

转别人的


想了解西藏的天葬文化、藏北比如骷髅墙吗?[url=http://www.]【雪域藏北论坛】[/url]给你诠释!
2007-04-03 22:07
hehe6021275
Rank: 1
等 级:新手上路
帖 子:17
专家分:0
注 册:2006-6-6
收藏
得分:0 
回复:(zhjesse)面是我最近几天刚弄好的代码,它能够...
呵呵寫的好復雜呀!◎#
2007-04-04 12:31
honkin
Rank: 1
等 级:新手上路
帖 子:32
专家分:0
注 册:2007-3-22
收藏
得分:0 
回复:(大宋提刑官)求C#的登陆程序,连SQL2000的哪位...
zhjesse,

OleDbConnection conn = new OleDbConnection("Data Source=F:\\c#.net\\学生信息管理
你用绝对地址吗?这样不大好吧?

一切从菜鸟做起!
2007-04-05 09:07
liuminghui
Rank: 6Rank: 6
等 级:贵宾
威 望:20
帖 子:2882
专家分:0
注 册:2007-1-26
收藏
得分:0 
不算复杂,多看看就会了

海鸽 is My Lover!!
2007-04-05 09:38
hobby666
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2007-4-5
收藏
得分:0 

private void btn_ok_Click(object sender, System.EventArgs e)
{
string strUser,strPassword,strDept_id;

strUser=this.tbnusername.Text.ToString().Trim();
strPassword=this.tbnpassword.Text.ToString().Trim();
strDept_id=this.tbndept_id.Text.ToString().Trim();

if(strUser=="")
{
MessageBox.Show( "用户名不能为空!","提示",MessageBoxButtons.OK,MessageBoxIcon.Warning);
return;
}
if(strPassword=="")
{
MessageBox.Show( "密码不能为空!","提示",MessageBoxButtons.OK,MessageBoxIcon.Warning);
return;
}
if(strDept_id=="")
{
MessageBox.Show( "部门号不能为空!","提示",MessageBoxButtons.OK,MessageBoxIcon.Warning);
return;
}
// string strselect="SELECT username,password,dept_id FROM companydb.login WHERE username='"+strUser+"'";
// string source="Server=(LOCAL)\\NetSDK;Integrated security=SSPI;Database=companydb";
// string source="Server=127.0.0.1;uid=sa;pwd=123;database=companydb";
// string mysource="Data Source=172.16.5.37;Initial Catalog=companydb;Integrated Security=SSPI";
string mysource="Data Source=HOBBY;Initial Catalog=companydb;Integrated Security=SSPI";
SqlConnection conn=new SqlConnection(mysource);
try
{
conn.Open();
}
catch
{
MessageBox.Show("连接数据库失败","提示",MessageBoxButtons.OK ,MessageBoxIcon.Stop );
this.Cursor = Cursors.Default ;
return;
}

SqlCommand cmd = conn.CreateCommand();
cmd.CommandText="Select * from login where username='"+strUser+"'";

SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
if (dr["password"].ToString().Trim() ==strPassword && dr["dept_id"].ToString().Trim()==strDept_id )
{
// Form Form5=new Form();
// Form5.Show();
MessageBox.Show("系统登陆成功!");
Form4 Form_4=new Form4();
Form_4.Show();
// MessageBox.Show("Form5");
this.Hide();

}
else
{
MessageBox.Show("您输入的用户信息或密码不正确!","提示",MessageBoxButtons.OK,MessageBoxIcon.Warning);
}
}
else
{
MessageBox.Show("没有此用户");
}
dr.Close();
conn.Close();
return;

}

2007-04-05 13:57
快速回复:求C#的登陆程序,连SQL2000的哪位高手能帮帮我,我是新手。
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.012342 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved