asp.net登录页面代码 [英] asp.net login page code
本文介绍了asp.net登录页面代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在第26行显示错误.
its showing error in line number 26..
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;
public partial class home : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["RegconnectionString"].ConnectionString);
con.Open();
string cmdStr = "Select Count(*) from Registration where UserName='" + TextBox1.Text + "'";
SqlCommand Checkuser = new SqlCommand(cmdStr, con);
int temp = Convert.ToInt32(Checkuser.ExecuteScalar().ToString());
if (temp == 1)
{
string cmdstr2 = "Select Password from Registration where UserName='" + TextBox1 + "'";
SqlCommand pass = new SqlCommand(cmdstr2, con);
string password = pass.ExecuteScalar().ToString();
con.Close();
if (password == TextBox2.Text)
{
Session["New"] = TextBox1.Text;
Response.Redirect("gallery.aspx");
}
else
{
Label1.Visible = true;
Label1.Text = "Invalid Password...!!!";
}
}
else
{
Label1.Visible = true;
Label1.Text = "Invalid UserName...!!!";
}
}
}
推荐答案
嗨.
"pass.ExecuteScalar()"的结果可能为空值.
您不能调用null的ToString()方法.
hi.
the result of "pass.ExecuteScalar()" may be a null value.
You can''t call ToString() method of a null.
object password = pass.ExecuteScalar();
if (password != null)
{
//here you can use password
}
这篇关于asp.net登录页面代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文