主题:求助一个关于在asp中进行数据查询的问题
发表于:2009-04-19 15:19:45 楼主
页面代码: <head runat="server">
<title>无标题页 </title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server" Text="账号:"> </asp:Label>
<asp:TextBox ID="TextBox1" runat="server"> </asp:TextBox>
</div>
<asp:Label ID="Label2" runat="server" Text="密码:"> </asp:Label>
<asp:TextBox ID="TextBox2" runat="server"> </asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
<p>
<asp:Label ID="Label3" runat="server" Visible ="false" Text="欢迎光临"> </asp:Label>
</p>
<asp:AccessDataSource ID="AccessDataSource1" runat="server">
</asp:AccessDataSource>
</form>
</body>
</html>
在aspx.cs中的代码:
public partial class _Default : System.Web.UI.Page
{
private string scalar()
{
OdbcConnection con = new OdbcConnection(ConfigurationManager.ConnectionStrings["connection"].ConnectionString);
con.Open();
string n = this.TextBox1.Text.ToString();
string cmdtext = "select Pwd from UserInfo where userId=n";
OdbcCommand cmd = new OdbcCommand(cmdtext, con);
string bb = cmd.ExecuteScalar().ToString();
con.Close();
return bb;
}
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
string m=this.scalar();
string n=this.TextBox2.ToString();
if (m == n)
{
this.Label3.Visible = true;
}
else
{
this.Label3.Text = "您的密码错误";
this.Label3.Visible = true;
}
}
}麻烦哪位老大给找找错误。。 string n = this.TextBox1.Text.ToString();
string cmdtext = "select Pwd from UserInfo where userId=n";//应该是在这一段的错误目的是查询输入的用户的密码是否正确如果正确就显示登路
//成功
OdbcCommand cmd = new OdbcCommand(cmdtext, con); //这一段的问题希望大家给解决一下
string bb = cmd.ExecuteScalar().ToString();
页面代码: <head runat="server">
<title>无标题页 </title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server" Text="账号:"> </asp:Label>
<asp:TextBox ID="TextBox1" runat="server"> </asp:TextBox>
</div>
<asp:Label ID="Label2" runat="server" Text="密码:"> </asp:Label>
<asp:TextBox ID="TextBox2" runat="server"> </asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
<p>
<asp:Label ID="Label3" runat="server" Visible ="false" Text="欢迎光临"> </asp:Label>
</p>
<asp:AccessDataSource ID="AccessDataSource1" runat="server">
</asp:AccessDataSource>
</form>
</body>
</html>
在aspx.cs中的代码:
public partial class _Default : System.Web.UI.Page
{
private string scalar()
{
OdbcConnection con = new OdbcConnection(ConfigurationManager.ConnectionStrings["connection"].ConnectionString);
con.Open();
string n = this.TextBox1.Text.ToString();
string cmdtext = "select Pwd from UserInfo where userId=n";
OdbcCommand cmd = new OdbcCommand(cmdtext, con);
string bb = cmd.ExecuteScalar().ToString();
con.Close();
return bb;
}
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
string m=this.scalar();
string n=this.TextBox2.ToString();
if (m == n)
{
this.Label3.Visible = true;
}
else
{
this.Label3.Text = "您的密码错误";
this.Label3.Visible = true;
}
}
}麻烦哪位老大给找找错误。。 string n = this.TextBox1.Text.ToString();
string cmdtext = "select Pwd from UserInfo where userId=n";//应该是在这一段的错误目的是查询输入的用户的密码是否正确如果正确就显示登路
//成功
OdbcCommand cmd = new OdbcCommand(cmdtext, con); //这一段的问题希望大家给解决一下
string bb = cmd.ExecuteScalar().ToString();