C#2010做航空机票预订管理系统登录界面有问题
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
namespace 航空机票预订管理系统
{
public class LinkDatabase
{
string strcon = @"Server=(local);database=book_ticket;uid=sa;pwd=920220";
public bool updatedb(string sql)
{
SqlConnection con = new SqlConnection(strcon);
con.Open();
try
{
SqlCommand cmd = new SqlCommand(sql, con);
cmd.ExecuteNonQuery();
return true;
}
catch
{
con.Close();
return false;
}
}
public DataTable dsresult(string ordersql)
{
SqlConnection conn = new SqlConnection(strcon);
conn.Open();
SqlDataAdapter adapter = new SqlDataAdapter(ordersql, conn);
DataTable dataset = new DataTable();
adapter.Fill(dataset);
conn.Close();
return dataset;
}
}
}
-------------------------连接数据库
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 航空机票预订管理系统
{
public partial class login : Form
{
public static bool canlog = false;
public string struser = "";
public int UType = 0;
private DataTable ds = new DataTable();
private DataRow myrow;
private string sendstrsql = "SELECT * FROM 员工";
//查用户表语句
public login()
{
InitializeComponent();
}
private void btn_login_Click(object sender, EventArgs e)
{
LinkDatabase link = new LinkDatabase();
this.ds = link.dsresult(sendstrsql);
for (int i = 0; i < ds.Rows.Count; i++)
{
this.myrow = ds.Rows[i];
if (myrow[0].ToString().Trim() == this.txt_ID.Text.ToString().Trim() && myrow[1].ToString().Trim() == this.txt_pw.Text.ToString().Trim())
{
canlog = true;
struser = myrow[0].ToString().Trim();
UType = Convert.ToInt32(myrow[2]);
this.Close();
return;
}
}
MessageBox.Show("您输入的用户名或密码不正确!");
return;
}
private void btn_cancel_Click(object sender, EventArgs e)
{
canlog = false;
this.Close();
}
}
}
-------------------登录界面代码
登录用户名是员工姓名,登录密码是员工编号,但是输入之后告诉我用户名或密码不正确!
想请问:1.要在SQL Server的查询分析器里编写哪些代码???????
2.怎样修改才能输入员工姓名和编号后登录成功?!!!!跪谢!!!!!
下面是数据库的员工表:
[最优解释]
private void btn_login_Click(object sender, EventArgs e)
{
sendstrsql = "SELECT * FROM 员工 WHERE 员工姓名='"+this.txt_ID.Text.ToString().Trim()+"' AND 员工编号='"+this.txt_pw.Text.ToString().Trim()+"'";
LinkDatabase link = new LinkDatabase();
this.ds = link.dsresult(sendstrsql);
if(ds.Rows.Count!=1)
{
MessageBox.Show("您输入的用户名或密码不正确!");
return;
}
this.myrow = ds.Rows[0];
if (myrow[0].ToString().Trim() == this.txt_ID.Text.ToString().Trim() && myrow[1].ToString().Trim() == this.txt_pw.Text.ToString().Trim())
{
canlog = true;
struser = myrow[0].ToString().Trim();
UType = Convert.ToInt32(myrow[2]);
this.Close();
}
}
-------------------登录界面代码
登录用户名是员工姓名,登录密码是员工编号,但是输入之后告诉我用户名或密码不正确!
想请问:1.要在SQL Server的查询分析器里编写哪些代码???????
2.怎样修改才能输入员工姓名和编号后登录成功?!!!!跪谢!!!!!
下面是数据库的员工表:
1.SELECT * FROM 员工 WHERE 员工姓名=‘钱一’ AND 员工编号=211001
查询这个纪录如果存在 1条就是成功了。
当然判断的方式很多种