更新时间2019-01-05 09:18:30
“System.ArgumentException”类型的未经处理的异常在 System.Data.dll 中发生,大神帮帮忙!
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Configuration;
namespace 用户登录
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btnOK_Click(object sender, EventArgs e)
{
string uername = txtName.Text.Trim();
string pwd = txtPwd.Text.Trim();
string constr = "Sever=.;DataBase=manager;Integrated Security=True";
//建立SqlConnection对象
SqlConnection con = new SqlConnection(constr);
//打开连接
con.Open();
//指定sql语句
SqlCommand com = new SqlCommand("select account,password from Admin where account='" + uername + "'and password'" + pwd + "'", con);
//建立sqlDataAddpter和DataSet对象
SqlDataAdapter da = new SqlDataAdapter(com);
DataSet ds = new DataSet();
int n=da.Fill(ds,"Admin");
if (n!=0)
{
MessageBox.Show("登录成功!", "提示");
label1.Visible = false;
txtName.Visible = false;
txtPwd.Visible = false;
}
else
{
MessageBox.Show("用户名或密码错误,请重新输入", "提示");
txtName.Text = "";
txtPwd.Text = "";
txtName.Focus();
}
con.Close();
}
}
}
"'and password'" 这个地方,password后面少了个“=”号