错误 1 “System.Data.SqlClient.SqlConnection”不包含“ExecuteScalar”的定义,并且找不到可接受类型为“System.Data.SqlClient.SqlConnection”的第一个参数的扩展方法“ExecuteScalar”(是否缺少 using 指令或程序集引用?) C:\Users\张小坨\Desktop\liuyanban\login.aspx.cs 39 22 C:\...\liuyanban\数据库名字message 
有表:dbo.mes
dbo.userID  user    pwd    name   qq    email              interest    type
1   1     111111   1      1     [email protected]    1            1using System;
using System.Configuration;
using System.Collections;
using System.Data;
//using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
//using System.Xml.Linq;
using System.Data.SqlClient;
public partial class login : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {
      
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
               Response.Redirect("zhuce.aspx");
    }
    protected void Button2_Click(object sender, EventArgs e)
    { 
        string name = text_user.Text;
        string pwd = text_pwd.Text;
        SqlConnection conn = new SqlConnection();
        conn.ConnectionString = "server=ABD\\SQLEXPRESS;DataBase=message;Integrated Security=SSPI";
        conn.Open();
        string sqlstr = "select count(*)from user_user where user='" + name + "'and pwd='" + pwd + "'";
        SqlCommand comm = new SqlCommand(sqlstr, conn);
        int i = Convert.ToInt32(conn.ExecuteScalar());
        conn.Close();
        if (i > 0)
        {
            Response.Redirect("liuyanban.aspx");
        }
        else
            this.Label4.Text = "登陆失败,用户名或密码错误!请重试。";       // Response.Redirect("liuyanban.aspx");    }}

解决方案 »

  1.   


    好了,可是出现这个:
    protected void Button2_Click(object sender, EventArgs e)
      {  
      string name = text_user.Text;
      string pwd = text_pwd.Text;
      SqlConnection conn = new SqlConnection();
      conn.ConnectionString = "server=ABD\\SQLEXPRESS;DataBase=message;Integrated Security=SSPI";
      conn.Open();
      string sqlstr = "select count(*)from user_user where user='" + name + "'and pwd='" + pwd + "'";
      SqlCommand comm = new SqlCommand(sqlstr, conn);
      int i = Convert.ToInt32(conn.ExecuteScalar());  conn.Close();
      if (i > 0)
      {
      Response.Redirect("liuyanban.aspx");
      }
      else
      this.Label4.Text = "登陆失败,用户名或密码错误!请重试。";  // Response.Redirect("liuyanban.aspx");  }说用户代码未处理SqlException
    关键字‘user’附近有语法错误
      

  2.   


    using(SqlConnection conn = new SqlConnection(""))
    {
      conn.Open();
      SqlCommand  comm  = new SqlCommand("select count(8) from ....", conn);  nt iCount = (int) comm.ExecuteScalar();
    }
      

  3.   

    string sqlstr = "select count(*) from user_user where [user]='" + name + "' and pwd='" + pwd + "'";
      

  4.   

    string sqlstr = "select count(*)from user_user where user='" + name + "'and pwd='" + pwd + "'";
     你的数据库表名不是user 吗 
      

  5.   

    user 是保留字,如果用于字段名需要用中括号包起来,[user]