System.Data.SqlClient.SqlException类型的未经处理的异常在 System.Data.dll 中发生
其他信息:关键字'user'附近有语法错误。usingSystem;usingSystem.Collections.Generic;usingSystem.Compone...
其他信息: 关键字 'user' 附近有语法错误。
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;
namespace 用户3
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void label2_Click(object sender, EventArgs e)
{
}
private void btn_exit_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void label1_Click(object sender, EventArgs e)
{
Random r = new Random();
int i = r.Next(1000, 9999);
lab_yzm.Text = i.ToString();
}
private void btn_login_Click(object sender, EventArgs e)
{
if (txt_yz.Text == lab_yzm.Text)
{
string user = txt_user.Text;
string pwd = txt_pwd.Text;
//string connStr = ;
SqlConnection conn = new SqlConnection("Data Source=(local);Initial Catalog=user;Integrated Security=True");
conn.Open();
SqlCommand cmd = conn.CreateCommand();
cmd.CommandText = "select *from user where USERNAME='"+user+"'and PSW='"+pwd+"'";
SqlDataReader reader = cmd.ExecuteReader();
conn.Close();
if(reader.Read())
{
MessageBox.Show("登录成功"); }
else { MessageBox.Show("登录失败"); }
}
else
{
MessageBox.Show("验证码输入错误,请重新输入");
Random r = new Random();
int i = r.Next(1000, 9999);
lab_yzm.Text = i.ToString();
}
}
}
}
请问这个程序哪里错了? 展开
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;
namespace 用户3
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void label2_Click(object sender, EventArgs e)
{
}
private void btn_exit_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void label1_Click(object sender, EventArgs e)
{
Random r = new Random();
int i = r.Next(1000, 9999);
lab_yzm.Text = i.ToString();
}
private void btn_login_Click(object sender, EventArgs e)
{
if (txt_yz.Text == lab_yzm.Text)
{
string user = txt_user.Text;
string pwd = txt_pwd.Text;
//string connStr = ;
SqlConnection conn = new SqlConnection("Data Source=(local);Initial Catalog=user;Integrated Security=True");
conn.Open();
SqlCommand cmd = conn.CreateCommand();
cmd.CommandText = "select *from user where USERNAME='"+user+"'and PSW='"+pwd+"'";
SqlDataReader reader = cmd.ExecuteReader();
conn.Close();
if(reader.Read())
{
MessageBox.Show("登录成功"); }
else { MessageBox.Show("登录失败"); }
}
else
{
MessageBox.Show("验证码输入错误,请重新输入");
Random r = new Random();
int i = r.Next(1000, 9999);
lab_yzm.Text = i.ToString();
}
}
}
}
请问这个程序哪里错了? 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
您可能需要的服务
百度律临官方认证律师咨询
平均3分钟响应
|
问题解决率99%
|
24小时在线
立即免费咨询律师
18219人正在获得一对一解答
西安夜猫子4分钟前提交了问题
郑州都市传说6分钟前提交了问题
广州萤火虫6分钟前提交了问题