嗨我创建登录页面...但它不会与数据库连接 [英] hi iam creating login page... but it doesn'tgoes to database connection
问题描述
嗨
使用System;
使用System。 Collections.Generic;
使用System.Linq;
使用System.Web;
使用System.Web.UI;
使用System.Web.UI.WebControls;
使用System.Data.SqlClient;
使用System.Configuration;
public partial class登录:System.Web.UI.Page
{
protected void Page_Load(object sender,EventArgs e)
{
}
protected void Button_Login_Click(object sender,EventArgs e)
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings [RegistrationConnectionString]。ConnectionString);
con.Open();
string checkuser =从UserData中选择count(*),其中[User Name] ='+ TextBoxUserName.Text +';
SqlCommand com = new SqlCommand(checkuser,con);
int temp = Convert.ToInt32(com.ExecuteScalar()。ToString());
con.Close();
if(temp == 1)
{
con.Open();
string checkPasswordQuery =从UserData选择密码,其中[User Name]'+ TextBoxUserName.Text +' ;
SqlCommand passCom = new SqlCommand(checkPasswordQuery,con);
string password = passCom.ExecuteScalar()。ToString()。Replace(,) ;
if(password == TextBoxPassword.Text)
{
Session [New] = TextBoxUserName.Text;
Response.Write(密码正确);
Response.Redirect(Mnager.aspx);
}
else
{
Response.Write(密码不正确);
}
}
}
}
con.Open();
string checkuser =从UserData中选择count(*),其中[User Name] ='+ TextBoxUserName.Text +';
SqlCommand com = new SqlCommand(checkuser,con);
SqlDatareader dr = com.executereader();
if(dr.read())
{
int temp = dr [0];
}
con.Close();
这样可行
我认为你的代码是正确的。做一件事
逐行调试你的代码(f11),然后复制Checkuser值并直接从Sql运行server .....
检查命名空间 - 使用system.data.sqlclient是否在命名空间中添加.....如果不是......添加它们
hi
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;
public partial class Login : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button_Login_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["RegistrationConnectionString"].ConnectionString);
con.Open();
string checkuser = "select count(*) from UserData where [User Name]='" + TextBoxUserName.Text + "'";
SqlCommand com = new SqlCommand(checkuser, con);
int temp = Convert.ToInt32(com.ExecuteScalar().ToString());
con.Close();
if (temp == 1)
{
con.Open();
string checkPasswordQuery = "select password from UserData where [User Name]'" + TextBoxUserName.Text + "'";
SqlCommand passCom = new SqlCommand(checkPasswordQuery, con);
string password = passCom.ExecuteScalar().ToString().Replace(" ","");
if (password == TextBoxPassword.Text)
{
Session["New"] = TextBoxUserName.Text;
Response.Write("Password is correct");
Response.Redirect("Mnager.aspx");
}
else
{
Response.Write("Password is not correct");
}
}
}
}
con.Open(); string checkuser = "select count(*) from UserData where [User Name]='" + TextBoxUserName.Text + "'"; SqlCommand com = new SqlCommand(checkuser, con); SqlDatareader dr = com.executereader(); if(dr.read()) { int temp = dr[0]; } con.Close();
this will work fine
I think your code is correct .Do one thing
Debugg ur code line by line (f11) ,then copy the Checkuser value and run directly from the Sql server.....
Check whether namespace-- using system.data.sqlclient is added up in namespace or not.....if not...add them
这篇关于嗨我创建登录页面...但它不会与数据库连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!