<%@ Page Language="C#" %>
<%@ Import Namespace="System.Data"%>
<%@ Import Namespace="System.Data.SqlClient" %>
<script runat="server">
protected void Button1_Click(object sender, EventArgs e)
{
string str = "Data Source=2642A6705BA0444;Initial Catalog=luntan;Integrated Security=True";
SqlConnection Conn=new SqlConnection (str);
string selectr = "select count(*) from users where userID =" + TB_name.Text + " and pwd= " + TB_pwd.Text + " ";
SqlCommand cmd=new SqlCommand (selectr,Conn);
Conn.Open();
char flag =(char)cmd.ExecuteScalar(); //运行输入gg时显示:列名 'gg' 无效。列名 'gg' 无效。
Conn.Close(); //select语句变成"select count(*) from users where userID =gg and pwd= gg "
if (flag==null)//用户名存在
{
Label1.Text="对不起用户名和密码不服,请重新输入!";
TB_name.Text="";
TB_pwd.Text = "";
}
else
{
Response.Redirect("http://www.njupt.edu.cn/");
}
}
<%@ Import Namespace="System.Data"%>
<%@ Import Namespace="System.Data.SqlClient" %>
<script runat="server">
protected void Button1_Click(object sender, EventArgs e)
{
string str = "Data Source=2642A6705BA0444;Initial Catalog=luntan;Integrated Security=True";
SqlConnection Conn=new SqlConnection (str);
string selectr = "select count(*) from users where userID =" + TB_name.Text + " and pwd= " + TB_pwd.Text + " ";
SqlCommand cmd=new SqlCommand (selectr,Conn);
Conn.Open();
char flag =(char)cmd.ExecuteScalar(); //运行输入gg时显示:列名 'gg' 无效。列名 'gg' 无效。
Conn.Close(); //select语句变成"select count(*) from users where userID =gg and pwd= gg "
if (flag==null)//用户名存在
{
Label1.Text="对不起用户名和密码不服,请重新输入!";
TB_name.Text="";
TB_pwd.Text = "";
}
else
{
Response.Redirect("http://www.njupt.edu.cn/");
}
}
string selectr = "select count(*) from users where userID ='" + TB_name.Text + "' and pwd= '" + TB_pwd.Text + "' ";
试试
Object reference not set to an instance of an object.