以下这段代码为Login登录界面的代码:using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Data.Sql;
using System.Configuration;
namespace PictureManager
{
public partial class Login : Form
{
public Login()
{
InitializeComponent();
} private void Login_Load(object sender, EventArgs e)
{ } private void btnLogin_Click(object sender, EventArgs e)
{
if (this.txtUserName.Text == "")
{
MessageBox.Show("用户名不能为空!", "错误");
}
else if (this.txtPassWord.Text == "")
{
MessageBox.Show("密码不能为空!", "错误");
}
if (CheckUser() > 0)
{
PicManager pic = new PicManager();
pic.Show();
this.Hide();
}
else
{
MessageBox.Show("用户名或密码不正确");
} }
public int CheckUser()
{
if (this.txtUserName.Text == "")
{
MessageBox.Show("用户名不能为空!", "错误");
}
else if (this.txtPassWord.Text == "")
{
MessageBox.Show("密码不能为空!", "错误");
}
string str = System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"];
SqlConnection conn = new SqlConnection(str);
SqlCommand cmd = new SqlCommand("Login", conn); cmd.CommandType = CommandType.StoredProcedure;
SqlParameter UserName = new SqlParameter("@username", SqlDbType.VarChar, 50);
UserName.Value = this.txtUserName.Text;
cmd.Parameters.Add(UserName); SqlParameter PassWord = new SqlParameter("@pwd", SqlDbType.VarChar, 50);
PassWord.Value = this.txtPassWord.Text;
cmd.Parameters.Add(PassWord); SqlParameter sp = new SqlParameter("@return", SqlDbType.Int, 4); sp.Direction = ParameterDirection.Output;
cmd.Parameters.Add(sp); try
{
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
int n = (int)(sp.Value);
return n;
}
catch
{
return 0;
} } private void btnCancel_Click(object sender, EventArgs e)
{
txtUserName.Text = "";
txtPassWord.Text = "";
}
}
}
界面
但是就是登录不了,登录需要连接数据库里表的用户名和密码来验证。
又高手帮忙谢谢了。
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Data.Sql;
using System.Configuration;
namespace PictureManager
{
public partial class Login : Form
{
public Login()
{
InitializeComponent();
} private void Login_Load(object sender, EventArgs e)
{ } private void btnLogin_Click(object sender, EventArgs e)
{
if (this.txtUserName.Text == "")
{
MessageBox.Show("用户名不能为空!", "错误");
}
else if (this.txtPassWord.Text == "")
{
MessageBox.Show("密码不能为空!", "错误");
}
if (CheckUser() > 0)
{
PicManager pic = new PicManager();
pic.Show();
this.Hide();
}
else
{
MessageBox.Show("用户名或密码不正确");
} }
public int CheckUser()
{
if (this.txtUserName.Text == "")
{
MessageBox.Show("用户名不能为空!", "错误");
}
else if (this.txtPassWord.Text == "")
{
MessageBox.Show("密码不能为空!", "错误");
}
string str = System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"];
SqlConnection conn = new SqlConnection(str);
SqlCommand cmd = new SqlCommand("Login", conn); cmd.CommandType = CommandType.StoredProcedure;
SqlParameter UserName = new SqlParameter("@username", SqlDbType.VarChar, 50);
UserName.Value = this.txtUserName.Text;
cmd.Parameters.Add(UserName); SqlParameter PassWord = new SqlParameter("@pwd", SqlDbType.VarChar, 50);
PassWord.Value = this.txtPassWord.Text;
cmd.Parameters.Add(PassWord); SqlParameter sp = new SqlParameter("@return", SqlDbType.Int, 4); sp.Direction = ParameterDirection.Output;
cmd.Parameters.Add(sp); try
{
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
int n = (int)(sp.Value);
return n;
}
catch
{
return 0;
} } private void btnCancel_Click(object sender, EventArgs e)
{
txtUserName.Text = "";
txtPassWord.Text = "";
}
}
}
界面
但是就是登录不了,登录需要连接数据库里表的用户名和密码来验证。
又高手帮忙谢谢了。
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货