用C#编写登陆界面

来源:百度知道 编辑:UC知道 时间:2024/05/31 17:58:40
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 zhulihuan
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button2_Click(object sender, EventArgs e)
{
this.Close();
}

private void button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("server=localhost; uid=sa; pwd=123; database=mydb");

con.Open();
string strSql = " select * from login where user=' " + textBox1.Text + " ' and psw=' " + textBox2.Text + " ' ";
SqlCommand myComman

private void button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("server=127.0.0.1,7788;uid=sa;pwd=sa;database=myzone");
con.Open();
string strSql = "select * from test where name='"+this.textBox1.Text+"' and pwd='"+this.textBox2.Text+"' ";
SqlCommand cmd = new SqlCommand(strSql, con);
SqlDataReader sdr = cmd.ExecuteReader();
if (sdr.HasRows)
{
MessageBox.Show("用户名和密码正确!");

}
else
MessageBox.Show("用户名和密码不正确!");
con.Close();
}

这是我刚刚写的 按照我的环境写的 你看这修改成你那边的环境就行了,

在判断之前跟一下或者给一个断点……
按Shift+F9看一下read对象的RowCount……就找到问题所在了……
程序是不能这样写的……

你打开了con.Open();
怎么不关闭啊!con.close()

else
MessageBox.Show("用户名和密码不正确!");
}
}

改为

else
{
MessageBox.Show("用户名和密码不正确!");
}

private void button