using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BLL;
using DAL;
namespace Library1.back.bookxinxi
{
    public partial class bookupdate : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                string book_name = Request.QueryString["book_name"];                bookinfo book = new bookinfo();
                TBname.Text = book.FindBybookname(book_name).Book_name;
                TBnumber.Text = book.FindBybookname(book_name).Book_number;
                TBstorage.Text = book.FindBybookname(book_name).Book_storage;
                TBborrow.Text = book.FindBybookname(book_name).Book_borrow;
                TBauthor.Text = book.FindBybookname(book_name).Book_author;
                TBtype.Text = book.FindBybookname(book_name).Book_type;
                TBdate.Text = book.FindBybookname(book_name).Publish_date;
                TBpublisher.Text = book.FindBybookname(book_name).Publisher;
                TBprice.Text = book.FindBybookname(book_name).Book_price;
                TBcase.Text = book.FindBybookname(book_name).Book_case;
            }
        }        protected void BTupdate_Click(object sender, EventArgs e)
        {
            booki b = new booki();
            bookinfo book = new bookinfo();
            b.Book_name = TBname.Text.Trim();
            b.Book_number = TBnumber.Text.Trim();
            b.Book_storage = TBstorage.Text.Trim();
            b.Book_borrow = TBborrow.Text.Trim();
            b.Book_author = TBauthor.Text.Trim();
            b.Book_type = TBtype.Text.Trim();
            b.Publish_date = TBdate.Text.Trim();
            b.Publisher = TBpublisher.Text.Trim();
            b.Book_price = TBprice.Text.Trim();
            b.Book_case = TBcase.Text.Trim();
            if (book.update(b))
            {                Response.Write("<script>alert('更新成功!')</script>");            }
            else
                Response.Write("<script>alert('更新失败!')</script>");
        }
    }
}
“/”应用程序中的服务器错误。'=' 附近有语法错误。说明: 执行当前 Web 请求期间,出现未经处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.Data.SqlClient.SqlException: '=' 附近有语法错误。源错误: 
行 57:                 da = new SqlDataAdapter(sql, con);
行 58:                 DataSet ds = new DataSet();
行 59:                 da.Fill(ds, table);
行 60:                 return ds;
行 61:             }源文件: E:\毕业相关\毕设程序\Library1\DAL\DBOperate.cs    行: 59 堆栈跟踪: 
[SqlException (0x80131904): '=' 附近有语法错误。]
   System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) +2073486
   System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +5064444
   System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning() +234
   System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +2275
   System.Data.SqlClient.SqlDataReader.ConsumeMetaData() +33
   System.Data.SqlClient.SqlDataReader.get_MetaData() +86
   System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) +311
   System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async) +987
   System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result) +162
   System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method) +32
   System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method) +141
   System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior) +12
   System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior behavior) +10
   System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +144
   System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +319
   System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, String srcTable) +92
   DAL.DBOperate.getDataSet(String sql, String table) in E:\毕业相关\毕设程序\Library1\DAL\DBOperate.cs:59[Exception: '=' 附近有语法错误。]
   DAL.DBOperate.getDataSet(String sql, String table) in E:\毕业相关\毕设程序\Library1\DAL\DBOperate.cs:64
   BLL.bookinfo.FindBybookname(String book_name) in E:\毕业相关\毕设程序\Library1\BLL\bookinfo.cs:105
   Library1.back.bookxinxi.bookupdate.Page_Load(Object sender, EventArgs e) in E:\毕业相关\毕设程序\Library1\Library1\back\bookxinxi\bookupdate.aspx.cs:20
   System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
   System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
   System.Web.UI.Control.OnLoad(EventArgs e) +91
   System.Web.UI.Control.LoadRecursive() +74
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2207版本信息: Microsoft .NET Framework 版本:4.0.30319; ASP.NET 版本:4.0.30319.272
说是有语法错误没检查出来啊String

解决方案 »

  1.   

    sql语句错误,很明显
    又是一个忙毕设的
    让我想起了自己的毕设啊
      

  2.   

    是啊是啊  快愁死我了  各种牛人方不方便加个qq啊   帮帮我啊   861073227
         public bool update(booki b)
            {
                string sql = "update book set book_name='" + b.Book_name + "',book_number='" + b.Book_number + "',book_storage='" + b.Book_storage + "',book_borrow='" + b.Book_borrow + "',book_author='"+ b.Book_author +"',book_type='"+ b.Book_type +"',publish_data='"+ b.Publish_date +"',publisher='"+ b.Publisher +"',book_price='"+ b.Book_price +"',book_case='"+ b.Book_case +"'";
                DBOperate.execSQL(sql);
                return true;
            }        //
            public booki FindBybookname(string book_name)
            {            string sql = "select * from book where book_name=" + book_name ;
                DataSet ds = DBOperate.getDataSet(sql, "book");
                //b.Boopk_image = ds.Tables[0].Rows[0][1].ToString();
                b.Book_name = ds.Tables[0].Rows[0][2].ToString();
                b.Book_number = ds.Tables[0].Rows[0][3].ToString();
                b.Book_storage = ds.Tables[0].Rows[0][4].ToString();
                b.Book_borrow = ds.Tables[0].Rows[0][5].ToString();
                b.Book_author = ds.Tables[0].Rows[0][6].ToString();
                b.Book_type = ds.Tables[0].Rows[0][7].ToString();
                b.Publish_date = ds.Tables[0].Rows[8][3].ToString();
                b.Publisher = ds.Tables[0].Rows[0][9].ToString();
                b.Book_price = ds.Tables[0].Rows[0][10].ToString();
                b.Book_case = ds.Tables[0].Rows[0][11].ToString();
                return b;
            }
      

  3.   

     string sql = "select * from book where book_name=" + book_name ;
     string sql = "select * from book where book_name='" + book_name"'"+ ;
      

  4.   

     string sql = "select * from book where book_name=" + book_name ;
    string sql = "select * from book where book_name='" + book_name+"'" ;
    要加单引号的。
      

  5.   


    楼上的说的确实是直观的错误LZ注意review你的代码,说说最严重的两个问题
    1.FindBybookname方法返回的是一个对象,而你赋值一个属性就查一下数据库,返回一个对象为了什么?
    2.SQL语句拼接很易出错,这个我想你问这个问题的时候就有体会吧,还会有什么问题?是不是有更好的方式,SQL参数化,多去了解一下...