日期:2014-05-20  浏览次数:20659 次

GridView出错!(初学者,希望大家不要笑话)
运行以后,在zonghe1.aspx.cs里面出错,提示:

用户代码未处理   SqlException
第1行: '> '附近有语法错误。

应该是zonghe.aspx.cs里面Button3代码里面有出错吧,但是现在还没找到!
相关代码如下:
public   partial   class   zonghe1   :   System.Web.UI.Page
{
        protected   void   Page_Load(object   sender,   EventArgs   e)
        {
                string   showCols   =   Request[ "showCols "];
                string   totalQuery   =   Request[ "totalQuery "];
                Label1.Text   =   "查询结果   "   +   totalQuery;
                //通过DataView控件显示符合查询条件的数据
                DataSet   ds=new   DataSet();
                SqlConnection   myConnection   =   new   SqlConnection( "server=localhost;uid=sa;pwd=860712;database=Northwind ");
                string   strSQL   =   "select "   +   showCols   +   "from   [Order   Details]   where "   +   totalQuery+ " ";
                SqlDataAdapter   myCommand   =   new   SqlDataAdapter(strSQL,   myConnection);
                myCommand.Fill(ds, "OrderDetails1 ");//问题就指示在这里
                if   (ds.Tables[ "OrderDetails1 "].Rows.Count   !=   0)
                {
                        GridView1.DataSource   =   ds.Tables[ "OrderDetails1 "].DefaultView;
                        GridView1.DataBind();
                }
                else
                {
                        Label1.Text   =   "没有符合查询条件的数据! ";
                }
        }
}

相关“第1行: '> '附近有语法错误”的代码:
protected   void   Button3_Click(object   sender,   EventArgs   e)
        {
                string   totalQuery= " ";//存放所有的查询条件
                string   showCols= " ";//存放要显示的所有字段
                //获取列表框中的所有查询条件
                if(ListBox1.Items.Count==0)
                {
                        Response.Write( " <script   language= 'javascript '> alert( '请设定查询条件! ') </script> ");
                }
                for(int   i=0;i <ListBox1.Items.Count;i++)