Dao.cs只有登陆

版权声明: https://blog.csdn.net/eds124/article/details/86545633
using System;
using System.Collections.Generic;
//using System.Linq;
using System.Web;

/// <summary>
///Dao 的摘要说明
/// </summary>
public class Dao
{
    private static string ConnectionString = "Data Source=.;Initial Catalog=mydata;User ID=sa;Password=Abcdefg1";

    public Dao()
    {

    }

    public static bool login(string username, string userpass)
    {
        //using (System.Web.UI.WebControls.SqlDataSource sds =new System.Web.UI.WebControls.SqlDataSource(ConnectionString,"select count(*) from t_user where username = @usernam and userpass = @userpass"))
        //{
        //    sds.SelectParameters.Add("username", username);
        //    sds.SelectParameters.Add("userpass", userpass);
        //    System.Collections.IEnumerable ie = sds.Select(System.Web.UI.DataSourceSelectArguments.Empty);
        //    System.Data.DataView dv = (System.Data.DataView)ie;
        //    object o = dv[0][0];
        //    return o;
        //}
        bool b = false;
        using (System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(ConnectionString))
        {
            
            System.Data.SqlClient.SqlCommand comm = conn.CreateCommand();
            comm.CommandText = "select count(*) from t_user where username = @username and userpass = @userpass";
            comm.Parameters.AddWithValue("username", username);
            comm.Parameters.AddWithValue("userpass", userpass);
            conn.Open();
            object o = comm.ExecuteScalar();
            int i = Convert.ToInt32(o);
            if (i > 0) {
                b = true;
            }
            
        }
        return b;
    }
}

猜你喜欢

转载自blog.csdn.net/eds124/article/details/86545633