《C#Web应用程序入门经典》学习到第五章碰到的问题
各位高手,正在学习这本书,学到第五章的search.aspx的例子的时候,
按照教材的程序输入时出现下列编译错误,实在不知问题出在哪里,请帮忙解决一下。
单击 new search搜索时出现下列错误
第 2 行: 'User ' 附近有语法错误。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息:
System.Data.SqlClient.SqlException: 第 2 行: 'User ' 附近有语法错误。
private void btnSearch_Click(object sender, System.EventArgs e)
{
StringBuilder sql = new StringBuilder();
// Limit maximum resultset size
sql.Append(@ "SELECT TOP ");
sql.Append(ConfigurationSettings.AppSettings[ "searchLimit "]);
sql.Append(@ "
[User].UserID, [User].FirstName, [User].LastName,
Place.PlaceID, Place.Name AS PlaceName,
PlaceType.Name AS PlaceType, PlaceType.TypeID,
TimeLapse.Name AS LapseName, TimeLapse.YearIn,
TimeLapse.MonthIn, TimeLapse.YearOut, TimeLapse.MonthOut
FROM [User]
LEFT OUTER JOIN TimeLapse ON
TimeLapse.UserID = [User].UserID
LEFT OUTER JOIN Place ON
Place.PlaceID = TimeLapse.PlaceID
LEFT OUTER JOIN PlaceType ON
Place.TypeID = PlaceType.TypeID
");
// Build the WHERE clause now
StringBuilder qry = new StringBuilder();
if (txtFirstName.Text != String.Empty)
{
qry.Append( "[User].FirstName LIKE '% ");
qry.Append(txtFirstName.Text).Append( "% ' AND ");
}
if (txtLastName.Text != String.Empty)
{
qry.Append( "[User].LastName LIKE '% ");
qry.Append(txtLastName.Text).Append( "% ' AND ");
}
if (cbPlace.SelectedItem.Value != "0 ")
{
qry.Append( "[Place].PlaceID = ' ");
qry.Append(cbPlace.SelectedItem.Value).Append( " ' AND ");
}
if (cbType.SelectedItem.Value != "0 ")
{
qry.Append( "[PlaceType].TypeID = ' ");