string strConnection="server=;database=;uid=;pwd=";
string strSQL="SELECT * FROM pslogin where u_name=";
SqlConnection objConnection=new SqlConnection(strConnection);
SqlCommand objCommand=new SqlCommand(strSQL,objConnection);
SqlDataReader objDataReader;
objConnection.Open();
objDataReader=objCommand.ExecuteReader();
if (objDataReader.Read() == false)
{
wel.Text = ".没有该用户名!";
return;}
else if
string strSQL="SELECT * FROM pslogin where u_name=";
SqlConnection objConnection=new SqlConnection(strConnection);
SqlCommand objCommand=new SqlCommand(strSQL,objConnection);
SqlDataReader objDataReader;
objConnection.Open();
objDataReader=objCommand.ExecuteReader();
if (objDataReader.Read() == false)
{
wel.Text = ".没有该用户名!";
return;}
else if
解决方案 »
- Image赋值
- 多值插入的问题
- asp.net 在服务器页面中可以使用多线程技术吗?谁能为我这样的需求提供一点思路?
- 是生命周期导致的问题么? 请各位大虾详细看看以下说明!
- 无法用Eval()绑定!
- 一个asp+access小网站上传到远程服务器上,浏览网址一切正常。但在本地机器上调试时,一点击“提交”,不是出现正常的界面,而是一个“
- asp.net2.0中使用母板好不好?使用用户控件好不好?是不是速度会变慢很多??
- 没有安装声卡的机器一旦有程序错误,就出现很大的"嘟嘟"声,真烦人,怎么样去掉或者变小?
- 大家帮个忙啊.看下这种数据展现形式该咋整啊~~~~~~~
- 关于Installshield修改XML的问题,求大神解决
- [求助]用最简单的方法将数据库中新填加的一条记录的ID,取出来,在线等!
- 高手帮我解决图片预览的问题!
没有 =》 false
有 =》 比较密码,不同 =》falsetrue
如果结果大于0 就存在
Session.Clear()
Session.Add("username", username.Text)
Dim pwd As String = password.Text
If Session("username") = "" Or pwd = "" Then
message = "<script language = javascript > alert('請輸入用戶名或密碼')</script>"
Call RegisterClientScriptBlock("alert", message)
End If
Dim MyCommand As SqlCommand
Dim myconnection As SqlConnection
Dim myadapter As SqlDataAdapter
Dim ds As DataSet
myconnection = New SqlConnection("server=localhost;uid=sa;pwd=sa;database=prj;")
Dim sqlstring As String
sqlstring = "select * from UT_user where Uid=" + "'" + Session("username") + "'"
MyCommand = New SqlCommand(sqlstring, myconnection)
Dim mydataread As SqlDataReader
MyCommand.Connection.Open()
mydataread = MyCommand.ExecuteReader
If (mydataread.Read() = False) Then
message = "<script language = javascript > alert('該用戶不存在')</script>"
Call RegisterClientScriptBlock("alert", message)
ElseIf (mydataread.Item(2) <> pwd) Then
message = "<script language = javascript > alert('密碼錯誤')</script>"
Call RegisterClientScriptBlock("alert", message)
Else
Response.Redirect("other.aspx")
End If MyCommand.Connection.Close()
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;namespace yemian1
{
/// <summary>
/// WebForm1 的摘要说明。
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.Label Label2;
protected System.Web.UI.WebControls.Label Label3;
protected System.Web.UI.WebControls.TextBox TextBox1;
protected System.Web.UI.WebControls.Button Button1;
protected System.Web.UI.WebControls.Button Button2;
protected System.Data.SqlClient.SqlConnection sqlConnection1;
protected System.Web.UI.WebControls.Label Label4;
protected System.Web.UI.WebControls.TextBox TextBox2;
private void Page_Load(object sender, System.EventArgs e)
{ Label1=new Label();
Label4=new Label();
label1.visible=true;
label4.visible=false;
// 在此处放置用户代码以初始化页面
} #region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.sqlConnection1 = new System.Data.SqlClient.SqlConnection();
this.Button1.Click += new System.EventHandler(this.Button1_Click);
//
// sqlConnection1
//
this.sqlConnection1.ConnectionString = "workstation id=\"GUJIANJU-3UH128\";packet size=4096;integrated security=SSPI;data s" +
"ource=\"GUJIANJU-3UH128\";persist security info=False;initial catalog=系统用户信息数据库";
this.Load += new System.EventHandler(this.Page_Load); }
#endregion private void Button1_Click(object sender, System.EventArgs e)
{
string b=new string (textbox2.text);
string a=new string (textbox1.text);
string strSQL="SELECT * FROM pslogin where LoginID=a ";
SqlCommand objCommand1=new SqlCommand(strSQL,sqlConnection1);
SqlDataReader objDataReader1;
sqlConnection1.Open();
objDataReader1=objCommand1.ExecuteReader();
if (objDataReader1.Read() == false)
{
label1.visible=false;
label4.visible=true;
}
else
{
string strSQL1="SELECT * FROM pslogin where pPassword =b ";
SqlCommand objCommand=new SqlCommand(strSQL1,sqlConnection1);
SqlDataReader objDataReader2;
sqlConnection1.Open();
objDataReader2=objCommand2.ExecuteReader();
if (objDataReader2.Read() == false)
{
label1.visible=false;
label4.visible=true;
}
else
(......)
;
}
}
}
}
总是出现 找不到类型或命名空间名称“label1"(是否缺少using指令或程序集引用)
找不到类型或命名空间名称“label4"(是否缺少using指令或程序集引用)
请问是什么问题?
{ Label1=new Label();
Label4=new Label();
label1.visible=true;
label4.visible=false;
// 在此处放置用户代码以初始化页面
}
/////
Label1=new Label();
Label4=new Label();
这两个太多余了!去掉就没事了!
原因是系统已经给你实例化了label1和label4
private void Button1_Click(object sender, System.EventArgs e)
{
string strSQL="SELECT * FROM pslogin where LoginID=Textbox1.text";
sqlCommand1=new SqlCommand(strSQL,sqlConnection1);
SqlDataReader objDataReader1;
sqlConnection1.Open();
objDataReader1=sqlCommand1.ExecuteReader();
if (objDataReader1.Read() == false)
{
Label1.Visible=false;
Label4.Visible=true;
}
else
{
string strSQL1="SELECT * FROM pslogin wherePassword =Textbox2.text ";
SqlCommand sqlCommand2=new SqlCommand(strSQL1,sqlConnection1);
SqlDataReader objDataReader2;
sqlConnection1.Open();
objDataReader2=sqlCommand2.ExecuteReader();
if (objDataReader2.Read() == false)
{
Label1.Visible=false;
Label4.Visible=true;
}
else
{ Response.Redirect("li.aspx");}
}
} private void Button2_Click(object sender, System.EventArgs e)
{TextBox1.Text="";
TextBox2.Text="";
}
}
}页面错误如下:
“/yemian1”应用程序中的服务器错误。
--------------------------------------------------------------------------------用户 'GUJIANJU-3UH128\ASPNET' 登录失败。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.Data.SqlClient.SqlException: 用户 'GUJIANJU-3UH128\ASPNET' 登录失败。源错误:
行 75: sqlCommand1=new SqlCommand(strSQL,sqlConnection1);
行 76: SqlDataReader objDataReader1;
行 77: sqlConnection1.Open();
行 78: objDataReader1=sqlCommand1.ExecuteReader();
行 79: if (objDataReader1.Read() == false)
源文件: d:\inetpub\wwwroot\yemian1\webform1.aspx.cs 行: 77 堆栈跟踪:
[SqlException: 用户 'GUJIANJU-3UH128\ASPNET' 登录失败。]
System.Data.SqlClient.ConnectionPool.GetConnection(Boolean& isInTransaction)
System.Data.SqlClient.SqlConnectionPoolManager.GetPooledConnection(SqlConnectionString options, Boolean& isInTransaction)
System.Data.SqlClient.SqlConnection.Open()
yemian1.WebForm1.Button1_Click(Object sender, EventArgs e) in d:\inetpub\wwwroot\yemian1\webform1.aspx.cs:77
System.Web.UI.WebControls.Button.OnClick(EventArgs e)
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
System.Web.UI.Page.ProcessRequestMain()