主题:跪求C#登陆程序
luffy0513
[专家分:0] 发布于 2009-04-11 23:15:00
我是个崭新崭新的新手 想用C#做个登陆程序 数据库是sql server 2000 但真是不会 一头雾水 因为是自学 真是懵了 怎么连接使用数据库也不会 麻烦大家 帮帮忙 我也好学习学习 谢谢 能多详细就多详细 最好还能介绍下怎么使用数据库 感恩不尽!!!!!!
回复列表 (共5个回复)
沙发
sevenjike [专家分:0] 发布于 2009-04-14 08:31:00
窗体会做吧。。做好窗体。。加个Button 再写个Click事件。。click事件里写查询语句就OK了。。如何写连接语句。。自己去看书吧。。写SQL语句要用到两包。。System.Data; 和 System.Data.SqlClient 好像是这两个吧。。我记不得了。。
3 楼
zxfzxfzxf12345 [专家分:0] 发布于 2009-04-25 01:37:00
public partial class Login : Form
{
SqlConnection con = new SqlConnection("server=(local);uid=sa;pwd=123456;database=data_base");
public Login()
{
InitializeComponent();
}
private void Login_Load(object sender, EventArgs e)
{
}
private void btnCancel_Click(object sender, EventArgs e)
{
this.Close();
}
private void btnLogin_Click(object sender, EventArgs e)
{
string name = this.txtName.Text.Trim();
string pwd = this.txtPwd.Text.Trim();
if (name == "")
{
MessageBox.Show("用户名不能为空!", "警告", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
txtName.Focus();
return;
}
if (pwd == "")
{
MessageBox.Show("密码不能为空!", "警告", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
txtPwd.Focus();
return;
}
if (ValidUser(name, pwd))
{
MainForm mainform = new MainForm();
this.Hide();
mainform.Show();
}
else
{
MessageBox.Show("用户名或密码错误!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
txtName.Text = "";
txtPwd.Text = "";
txtName.Focus();
return;
}
}
private bool ValidUser(string Name, string Pwd)
{
try
{
con.Open();
string cmd = "Select Count(*) from login Where name='" + Name + "' and password='" + Pwd + "'";
SqlCommand com = new SqlCommand(cmd, con);
int n = (int)com.ExecuteScalar();
if (n == 1)
{
return true;
}
else
{
return false;
}
}
catch (SqlException ex)
{
string Error = ex.ToString();
return false;
}
finally
{
con.Close();
}
}
}
}
4 楼
gamin1030 [专家分:0] 发布于 2009-05-08 09:50:00
同样新手,进来学习
5 楼
lyc8911330 [专家分:0] 发布于 2009-05-09 00:03:00
我也被这个愁着了,同样是新手,崭新崭新的···
我来回复