.net中一个登陆页面的问题

来源:百度知道 编辑:UC知道 时间:2024/05/27 02:54:06
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.OleDb;

public partial class admin_login : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this.usename.Text ="";
this.usepwd.Text ="";
}
}
protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
{
OleDbConnection oledbcon = new OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0;data source=" + HttpContext.Current.Server.MapPath(@"~/App_Data/tushu.mdb"));

第一:user 是保留字,用的时候是要加 [] -> [user] 以区别。
第二:
string sql="select count(*) from user where user_name='"+ usename.Trim() +" ' and user_pwd='"+ usepwd.Trim() +" ' ", oledbcon);
int count = Convert.ToInt32(cmd.ExecuteScalar());" 这条出错的语句,
你用Response.write(sql);的方式把它拿到查询分析器里面去执行。
有问题的话,那里调试好了,再拿进来。
第三:连接SQL语句和字符串的时候,最好用:String.Fromat()的方式:
如:String.Fromat("select * from Student where id={0} and name='{1}'",this.Textbox1.Text,this.Texbox2.Text);

select count(*) from user where user_name='yourname' and user_pwd='upwd'

你改成这样
select count(*) from [user] where user_name='yourname' and user_pwd='upwd'
某些字段不能使用系统关键字!
[字段]可以改善这个情况.

user是关键字啊大哥得加[]