qq_28785183 2015-06-06 15:29 采纳率: 0%
浏览 2016

为什么输入正确的username和userpass都显示登录失败

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 数据库
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string str = @"Data Source=XHTCS1VXKSW7AP4;Initial Catalog=book_system;Integrated Security=True";
SqlConnection conn = new SqlConnection(str);
conn.Open();
string selectsql = "select * from Login where username='" + textBox1.Text.Trim() +"' and Userpass='" + textBox2.Text.Trim() +"'";
SqlCommand cmd = new SqlCommand(selectsql,conn);
cmd.CommandType = CommandType.Text;
SqlDataReader sdr;
sdr = cmd.ExecuteReader();
if (sdr.Read())
{
label3.Text = "登录成功";
this.Close();
}
else
{
label3.Text = "登录失败";
return;
}
}
}
}

  • 写回答

6条回答 默认 最新

  • CeliaSun-Boy 2015-06-06 15:43
    关注

    图片说明

    评论

报告相同问题?

悬赏问题

  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题
  • ¥15 Python时间序列如何拟合疏系数模型