u012953466
xiangzi7758258
采纳率76.5%
2015-05-23 15:49 阅读 1.6k

asp.net遇到问题 小白求帮助

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void Button1_Click(object sender, EventArgs e)
{
    string mystr;
    SqlConnection myconn = new SqlConnection();
    mystr = "Data Source = localhost;Initial Catalog = eat;" + "Integrated Security = False; User Id = sa; Password = mgx";
    myconn.ConnectionString = mystr;
    try
    {
        myconn.Open();
        SqlCommand mycmd = new SqlCommand("select 密码 from eat where 账号 = @账号", myconn);
        mycmd.Parameters.Add("@账号",SqlDbType.VarChar).Value = TextBoxlogin1.Text.Trim();
        SqlDataReader dr = mycmd.ExecuteReader();
       /*if (dr[0].ToString() == TextBoxlogin2.Text.ToString())
        {
            Button1.Text = "成功";
        }
        else
            Button1.Text = "失败";*/
        //dr.Close();
    }
    catch
    { 

    }
    finally
    {
        myconn.Close();
    }
}

}

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

3条回答 默认 最新

  • 已采纳
    caozhy 从今以后生命中的每一秒都属于我爱的人 2015-05-23 15:59

    sql错误,检查下表名
    以及密码是不是nvarchar类型还是int类型

    点赞 评论 复制链接分享
  • u012953466 xiangzi7758258 2015-05-23 15:49

    在 System.Data.SqlClient.SqlException 中第一次偶然出现的“System.Data.dll”类型的异常

    点赞 评论 复制链接分享
  • u012953466 xiangzi7758258 2015-05-23 15:51

    图片说明

    点赞 评论 复制链接分享

相关推荐