web.config已做好,用户表也建好了,怎么根据用户名和密码来登录后就能看到数据库的内容,代码怎么写
public partial class _Default : System.Web.UI.Page 
{
    SqlConnection sms_conn;
    protected void Page_Load(object sender, EventArgs e)
    {
        string sms_connstr = System.Configuration.ConfigurationManager.AppSettings["sms_dbconn"];
        // 建立连接
        sms_conn = new SqlConnection(sms_connstr);          
      
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        string str_pwd = this.TextBox1.Text.Trim().Replace("'", "''");
        string sqlstr = "select username from user where username='"+ TextBox1.Text+"'and password=@password";
        SqlCommand cmd = new SqlCommand(sqlstr,sms_conn);
        cmd.Parameters.Add(new SqlParameter("@password", SqlDbType.VarChar,50));
        sms_conn.Open();
        SqlDataReader dr = cmd.ExecuteReader();
        if (dr.Read() == true)
        {
            Session["user"] = this.TextBox1.Text.Trim();//管理员用户,Session进行传值
                  FormsAuthentication.RedirectFromLoginPage(TextBox1.Text, false);
            sms_conn.Close();
        }
     
    }

解决方案 »

  1.   

    string sms_connstr = System.Configuration.ConfigurationManager.AppSettings["sms_dbconn"];========可能是这里取道了空值 null检查键 "sms_dbconn" 是否正确
      

  2.   

    原来是
    <appSettings>
         <add key="SMS_dbconn" value="server=.;Pooling=true;Min Pool Size=10;Max Pool Size=200;packet size=4096;data source=(local);initial catalog=SMSstudent;uid=sa;pwd=" />
         <add key="CrystalImageCleaner-AutoStart" value="true" />
         <add key="CrystalImageCleaner-Sleep" value="60000" />
         <add key="CrystalImageCleaner-Age" value="120000" />
     </appSettings>
    现在是
    <appSettings/>
        <connectionStrings>
            <add name="testConnectionString" connectionString="Data Source=A-873F05FBA6B84;Initial Catalog=test;Integrated Security=True"
                providerName="System.Data.SqlClient" />
        </connectionStrings>
    怎么改?