[求助]用户代码未处理
System.Data.SqlClient.SqlException刚学.NET,在看北大青鸟的教程,按照教程的内容写了一段代码,但是运行的时候提示出错。请求解答,我用的是VS2005
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class login : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string userName = Request.Form[ "userName "].ToString();
string userPwd = Request.Form.Get( "userPwd ").ToString();
SqlConnection con=new SqlConnection( "server=.;database=login;uid=sa;pwd=; ");
con.Open();
SqlCommand cmd=new SqlCommand( "select count(*) form login where userName= ' "+userName+ " ' and userPwd= ' "+userPwd+ " ' ", con);
int count=Convert.ToInt32(cmd.ExecuteScalar());
if(count> 0)
{
Response.Redirect( "main.aspx ");
}
else
{
Response.Redirect( "loginfail.html ");
}
}
}
错误提示就在这一行上:int count=Convert.ToInt32(cmd.ExecuteScalar());
详细的错误信息:
Message= "第 1 行: 'login ' 附近有语法错误。 "
Source= ".Net SqlClient Data Provider "
ErrorCode=-2146232060
Class=15
LineNumber=1
Number=170
Procedure= " "
Server= ". "
State=1
StackTrace:
在
System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
在 System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)