问题描述
“=”附近有语法错误行30:Adapter.SelectCommand=myCommand;行31:DataSetmyDs=newDataSet();行32:Adapter.Fill(myDs);行33:DataTablemyTable=myDs.Tables[0];行34:DataRowrow=myTable.Rows[0];具体代码如下usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Web;usingSystem.Web.UI;usingSystem.Web.UI.WebControls;usingSystem.Data;usingSystem.Data.SqlClient;publicpartialclassOrderDetail:System.Web.UI.Page{protectedvoidPage_Load(objectsender,EventArgse){if(!IsPostBack){Bind();}}publicvoidBind(){StringOrder_ID=Request.QueryString["Order_ID"];Stringsqlconn="DataSource=.;Database=YiYaoWang;IntegratedSecurity=True";SqlConnectionmyConnection=newSqlConnection(sqlconn);myConnection.Open();stringsql=string.Format("select*from[Order],OrderStatus,Order_detail,UserMsg,GoodsMsgwhereFID_user=User_IDand[Order].Status=OrderStatus.IDandOrder_ID="+Order_ID);SqlCommandmyCommand=newSqlCommand(sql,myConnection);SqlDataAdapterAdapter=newSqlDataAdapter();Adapter.SelectCommand=myCommand;DataSetmyDs=newDataSet();Adapter.Fill(myDs);DataTablemyTable=myDs.Tables[0];DataRowrow=myTable.Rows[0];DataColumnc1=myTable.Columns["Order_Status"];DataColumnc2=myTable.Columns["UserName"];DataColumnc3=myTable.Columns["Phone"];DataColumnc4=myTable.Columns["OrderTime"];DataColumnc5=myTable.Columns["eMail"];DataColumnc6=myTable.Columns["Receiver"];DataColumnc7=myTable.Columns["Destination"];DataColumnc8=myTable.Columns["Delivery_num"];DataColumnc9=myTable.Columns["ReceiverTel"];LabelStatus.Text=row[c1].ToString();LabelUserName.Text=row[c2].ToString();LabelOrderTime.Text=row[c4].ToString();TextBoxReceiver.Text=row[c6].ToString();TextBoxDestination.Text=row[c7].ToString();TextBoxPhone1.Text=row[c9].ToString();GridView1.DataSource=myDs.Tables[0].DefaultView;GridView1.DataBind();Doublecountsum=0;Doublepricesum=0;for(inti=0;i<GridView1.Rows.Count;i++){stringp=Convert.ToString(GridView1.Rows[i].Cells[2].Text);Doubleprice=Convert.ToDouble(p.Remove(0,6));//删除人民币符号Doublecount=Convert.ToDouble(GridView1.Rows[i].Cells[3].Text);GridView1.Rows[i].Cells[4].Text="¥"+(price*count).ToString();countsum+=count;pricesum+=price*count;}//总计LabelSum.Text=pricesum.ToString();}protectedvoidTextBoxPhone1_TextChanged(objectsender,EventArgse){}protectedvoidButton3_Click(objectsender,EventArgse)//修改信息{StringOrder_ID=Request.QueryString["Order_ID"];Stringsqlconn="DataSource=.;Database=YiYaoWang;IntegratedSecurity=True";SqlConnectionmyConnection=newSqlConnection(sqlconn);myConnection.Open();stringsqlstr="update[Order]setReceiver='"+TextBoxReceiver.Text+"',Destination='"+TextBoxDestination.Text+"',ReceiverTel='"+TextBoxPhone1.Text+"'whereOrder_ID="+Order_ID;SqlCommandmyCommand=newSqlCommand(sqlstr,myConnection);myCommand.ExecuteNonQuery();myConnection.Close();Response.Redirect("Order.aspx");}protectedvoidButton1_Click(objectsender,EventArgse)//取消订单{StringOrder_ID=Request.QueryString["Order_ID"];Stringsqlconn="DataSource=.;Database=YiYaoWang;IntegratedSecurity=True";SqlConnectionmyConnection=newSqlConnection(sqlconn);myConnection.Open();stringsqlstr="update[Order]setStatus='1'whereOrder_ID="+Order_ID;SqlCommandmyCommand=newSqlCommand(sqlstr,myConnection);myCommand.ExecuteNonQuery();myConnection.Close();Response.Redirect("Order.aspx");}}求大神帮忙本人初学者
解决方案
解决方案二:
"select*from[Order],OrderStatus,Order_detail,UserMsg,GoodsMsgwhereFID_user=User_IDand[Order].Status=OrderStatus.IDandOrder_ID="+Order_ID这句生成的是什么样的sql?
解决方案三:
建议你还是调试一下,定位到哪个语句出了错误,这样一大段代码实在让人看着不舒服。
解决方案四:
sql语句报错啊stringsql=string.Format("select*from[Order],OrderStatus,Order_detail,UserMsg,GoodsMsgwhereFID_user=User_IDand[Order].Status=OrderStatus.IDandOrder_ID="+Order_ID);
这边你输出看看就知道问题在哪了
解决方案五:
stringsql=string.Format("select*from[Order],OrderStatus,Order_detail,UserMsg,GoodsMsgwhereFID_user=User_IDand[Order].Status=OrderStatus.IDandOrder_ID="+Order_ID);这个User_ID有定义吗
解决方案六:
你这个错误就是SQL语句的错误,把你拼的SQL语句放到查询分析器里面执行下看看哪边报错就很清楚了.
解决方案七:
whereOrder_ID="+Order_ID;这儿不应该是这样写吗:whereOrder_ID='"+Order_ID+"'";
解决方案八:
查看生成的sql语句
解决方案九:
stringsql=string.Format("select*from[Order],OrderStatus,Order_detail,UserMsg,GoodsMsgwhereFID_user=User_IDand[Order].Status=OrderStatus.IDandOrder_ID="+Order_ID);
Order_ID在数据库中是varchar或者char类型的时候需要在前后加上单引号,表示是字符串:stringsql=select*from[Order],OrderStatus,Order_detail,UserMsg,GoodsMsgwhereFID_user=User_IDand[Order].Status=OrderStatus.IDandOrder_ID=‘"+Order_ID+”’“);如果用string.format的话写法应该是这样:stringsql=string.Format("select*from[Order],OrderStatus,Order_detail,UserMsg,GoodsMsgwhereFID_user=User_IDand[Order].Status=OrderStatus.IDandOrder_ID='{0}'",Order_ID);试试看,不知道你数据库中Order_ID是什么类型;另外,不建议直接拼接SQL,这样容易注入
解决方案十:
这种错误你但凡单步调试下就找到了1、打断点,单步调试2、用sqlprofiler监控下提交到服务器的sql是神马东东把上面得到的sql语句拿到数据库执行下,错误就一目了然了