using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace RLHT_YXJ_WFA1
{
public partial class LogIn : Form
{
//string[] table=new string[20];
public LogIn()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
using (SqlConnection conn = new SqlConnection(@"Data Source=YXJ\SQLEXPRESS;AttachDBFilename=|DataDirectory|\Ceshi.mdf;Integrated Security=True;User Instance=true"))
{
conn.Open();
using (SqlCommand cmd = conn.CreateCommand())
{
cmd.CommandText="select user_name,user_pwd from Users Where user_name='"+this.textBox1.Text+"'";
using (SqlDataReader reader = cmd.ExecuteReader())
{
if (this.textBox1.Text == "")
MessageBox.Show("请输入您的用户名");
else if (this.textBox2.Text == "")
MessageBox.Show("请输入您的密码");
else if (reader.Read())
{
//用户名存在
string dbpassword = reader.GetString(reader.GetOrdinal("user_pwd"));
if (this.textBox2.Text == dbpassword)
{
//登陆成功
ShowUser showuser = new ShowUser(textBox1.Text);
showuser.Show();
}
else
{
//密码错误
MessageBox.Show("您所输入的密码错误");
this.textBox2.Text = null;
}
}
else
{
//用户名错误
MessageBox.Show("您所输入的用户名不存在");
this.textBox1.Text = null;
}
}
}
conn.Close();
conn.Dispose();
}
//数据访问出现问题,明明修改了数据库,但还是可以用修改前的老用户数据进行访问,是缓存问题?有知道的高手烦请解答。
//DataTable table = new DataTable();
//SqlDataAdapter da = new SqlDataAdapter();
//string connstr = @"Data Source=YXJ\SQLEXPRESS;AttachDBFilename=|DataDirectory|\Ceshi.mdf;Integrated Security=True;User Instance=true";
//SqlConnection connection = new SqlConnection(connstr);
//connection.Open();
//SqlCommand ca = new SqlCommand("select user_name,user_pwd from Users Where user_name='"+this.textBox1.Text+"'",connection);
//da.SelectCommand = ca;
//da.Fill(table);
//if (this.textBox1.Text == "")
// MessageBox.Show("请输入您的用户名");
//else if (this.textBox2.Text == "")
// MessageBox.Show("请输入您的密码");
//else if (table.Rows.Count == 0)
//{
// MessageBox.Show("您所输入的用户名不存在");
// this.textBox1.Text = null;
//}
//else if (table.Rows[0][0].ToString() != this.textBox2.Text)
//{
// MessageBox.Show("您所输入的密码错误");
// this.textBox2.Text = null;
//}
//else
//{
// System.Console.WriteLine(table.Rows[0][0].ToString());
// System.Console.WriteLine(this.textBox2.Text);
// MessageBox.Show(table.Rows[0][0].ToString());
// MessageBox.Show(this.textBox2.Text);
// ShowUser showuser = new ShowUser(textBox1.Text);
// showuser.Show();
//}
//connection.Close();
//table.Clear();
}
private void button3_Click(object sender, EventArgs e)
{
NewUser newuser=new NewUser();
newuser.Show();
}
private void button4_Click(object sender, EventArgs e)
{
textBox1.Clear();
textBox2.Clear();
}
private void button2_Click(object sender, EventArgs e)
{
this.Close();
}
}
}
参考:
SqlDataAdapter
http://baike.baidu.com/view/2978109.htm
DataTable
http://blog.csdn.net/hcw_peter/article/details/3980723
关于|DataDirectory|\:
Program.cs
static void Main()
{
string dataDir = AppDomain.CurrentDomain.BaseDirectory;
if (dataDir.EndsWith(@"\bin\Debug\") || dataDir.EndsWith(@"\bin\Release\"))
{
dataDir = System.IO.Directory.GetParent(dataDir).Parent.Parent.FullName;
AppDomain.CurrentDomain.SetData("DataDirectory", dataDir);
}
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new LogIn());
}
//这是为了在测试运行的时候,让项目里的数据库文件和程序Debug或Release运行里的数据库文件区别开,真正交付给客户的时候一般不需要这段代码。
分享到:
相关推荐
WFA登陆程序,登陆、注册、修改、删除用户等功能。 (visual studio 2010+oracle 10g)
C# 2015 编写的UDP服务器,客户端。 实现服务器客户端连接,客户端发送数据,服务端显示数据的功能。
一个简单的程序,药物数据主成份分析,采用常见方法
世界足协 1.引言 1.1什么是WFA? 波前对齐(WFA)算法是一... 该库可以执行通过基准测试工具进行评估,也可以通过调用WFA函数将其集成到您的代码中。 如果您有兴趣通过WFA库中实现或集成的其他算法对WFA进行benchmar
Farming-Market-WFA:此项目是我的Farming-Market项目的Windows窗体应用程序版本,集成在同一数据库中
wfa分配
WFA测试手册,802.11N测试手册,包含版本2.16和2.19;WFA认证;802.11N WFA认证。
Practise_WFA:练习WFA
公平分析我们使用python分析来自WFA的县公平STOP报告。 进度报告12/31/2020: 第1类博览会已分为年度csv文件。 STOP报告的内容和组织每年都在变化。 下一步将把多年来的功能提炼成具有凝聚力的博览会代表。 显然,...
11_SCBC_WFA_人力分析和人才洞察 v6.1.pptx
这些文件设计用于使用布林带作为进入和退出规则的配对交易策略的前瞻分析。 在此示例中,您将看到 5 对股票在 3 年期间进行了测试。 业绩分析部分包括盈亏、夏普比率和最大回撤。 我真的希望你能找到这个文件作为...
ESP8266&ESP32_WFA_Certification_and_Test_Guide__CN.zip
.archESP8266&ESP32_WFA_Certification_and_Test_Guide__CN.pdf
WFA-改变全球营销采购观念和贡献(英文)-2020.7-41页.pdf
WFA-改变全球营销采购观念和贡献(英文)-2020.7-41页2020精品报告.pdf
劳动力分析 ADS WFA 系统。
WFA&2CU-首席营销官的难题和优秀营销人员的标准(英文)-2020.6-39页.pdf
wfa_orchestra
在VS2010环境下,使用C#语言在chart控件下画曲线,同时根据鼠标的移动,在曲线上显示鼠标所在位置曲线上的点的坐标。
hostapd_0.6.9.orig.tar.gz 源码