今年写了一点代码
try
{
string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("App_Data//class.mdb");//ACCESS链接字符串
OleDbConnection con = new OleDbConnection(strConn); //OleDb链接类的实例化
con.Open();
string strSQL = "Select * FROM user where name='"+TextBox1.Text+"' and password='"+TextBox2.Text+"'"; //要执行的SQL语句
OleDbCommand com = new OleDbCommand(strSQL, con);
if (com.ExecuteScalar() != null)
{
Session["kk"] = TextBox1.Text;
Response.Redirect("NetWorkDisk.aspx");
con.Close();
}
else
{
// Response.Write("<script language='javascript'>alert('用户名或密码错误!')</script>");
Response.Redirect("Default.aspx");
con.Close();
}
}
运行的时候老是提示FORM子句出错,闹得我好郁闷,后来string strSQL = "Select * FROM user where name='"+TextBox1.Text+"' and password='"+TextBox2.Text+"'"; 这个语句改成:
string strSQL = "Select * FROM [user] where name='"+TextBox1.Text+"' and password='"+TextBox2.Text+"'";
这时就不会出错了,不过我不知道到底是什么原因,不知哪位高手知道原因。