新手,请帮忙改好这个代码,实现这个功能,登录成功后跳到FORM2窗口。请注意SQL连接字符串是不是有问题。改好还请指明问题出在哪,谢谢
private void LoginForm_Load(object sender, EventArgs e)
{
{
String userid = this.userid.Text;//这里是用户的文本框
String pwd = this.pwd.Text;//这里是密码框
string SqlStr = ("server=.; uid=sa; pwd=555411; database=TomDB");//数据库连接
SqlConnection conn = new SqlConnection(SqlStr);
conn.Open();//打开数据库
string sql = "select count(*) from userTB where userid = @userid AND password = @pwd ";//用户名和密码表连接
//SqlParameter[] parameters = {
// new SqlParameter("@userid", SqlDbType.VarChar, 20),
// new SqlParameter("@pwd", SqlDbType.VarChar, 30) };
SqlCommand com = new SqlCommand(sql, conn);
int a = (int)com.ExecuteScalar();//返回第一行第一列
if (a > 0 )
{
MessageBox.Show("登录成功");
}
else
{
MessageBox.Show("登录失败");
}
}