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;namespace WindowsApplication1
{
public partial class Form1 : Form
{
protected int counter = 0;
protected SqlConnection conn;
public Form1(SqlConnection connection)
{
conn = connection;
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
if (textBox1.Text == " " || textBox2.Text == " ")
{
MessageBox.Show("请输入用户名和密码", "提示");
return;
}
SqlCommand cmd1 = conn.CreateCommand();
cmd1.CommandText = string.Format("select[pass]from[管理员信息]where[user_id]='{0}'", textBox1.Text);
object oPassword = cmd1.ExecuteScalar();
if (oPassword == null)
{
MessageBox.Show("该用户不存在,请重新输入!", "提示");
return;
}
if (textBox2.Text == oPassword.ToString())
{
this.DialogResult = DialogResult.OK;
}
else
{
if (++this.counter == 3)
{
MessageBox.Show("您输入错误次数过多,请与管理员联系!", "提示");
this.DialogResult = DialogResult.Cancel;
}
else
{
MessageBox.Show("密码不正确,请重新输入!", "提示");
}
} }
}
}
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;namespace WindowsApplication1
{
public partial class Form1 : Form
{
protected int counter = 0;
protected SqlConnection conn;
public Form1(SqlConnection connection)
{
conn = connection;
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
if (textBox1.Text == " " || textBox2.Text == " ")
{
MessageBox.Show("请输入用户名和密码", "提示");
return;
}
SqlCommand cmd1 = conn.CreateCommand();
cmd1.CommandText = string.Format("select[pass]from[管理员信息]where[user_id]='{0}'", textBox1.Text);
object oPassword = cmd1.ExecuteScalar();
if (oPassword == null)
{
MessageBox.Show("该用户不存在,请重新输入!", "提示");
return;
}
if (textBox2.Text == oPassword.ToString())
{
this.DialogResult = DialogResult.OK;
}
else
{
if (++this.counter == 3)
{
MessageBox.Show("您输入错误次数过多,请与管理员联系!", "提示");
this.DialogResult = DialogResult.Cancel;
}
else
{
MessageBox.Show("密码不正确,请重新输入!", "提示");
}
} }
}
}
{
this.DialogResult = DialogResult.OK;
}
执行完这段代码,用户名和密码都正确,所以没啥显示的
{
conn = connection;
InitializeComponent();
}
构造窗体的时候需要传入一个connection 看下你有没有