日期:2014-05-19  浏览次数:20497 次

sql查询问题,比较复杂
在一个页面中我方了一个gridview1,sqldatasource来显示数据(已经连接好了),在输入框中设置查询的关键字,我的查询是这样写的:
protected   void   Button1_Click(object   sender,   EventArgs   e)
        {
                SqlConnection   conn;
                SqlCommand   mycommned;
                SqlDataReader   myreader;
                SqlParameter   str_temp;
                int   listindex;

                listindex   =   0;
                listindex   =   DropDownList1.SelectedIndex;
                conn   =   new   SqlConnection();
                conn.ConnectionString   =   ConfigurationManager.ConnectionStrings[ "jwglConn "].ConnectionString;

                mycommned   =   new   SqlCommand();
                switch   (listindex)
                {
                        case   0:   mycommned.CommandText   =   "select   *   from   class_tabl   ";
                                        break;
                        case   1:   mycommned.CommandText   =   "select   *   from   class_tabl   where   class_id     like   '%@ "+TextBox2.Text.Trim()+ "% ' ";
                                        break;
                    //     case   2:   mycommned.CommandText   =   "select   *   from   class_tabl   ";
                    //     case   3:   mycommned.CommandText   =   "select   *   from   class_tabl   ";
                      //   case   4:   mycommned.CommandText   =   "select   *   from   class_tabl   ";
                }
                mycommned.CommandType   =   CommandType.Text;
                mycommned.Connection   =   conn;

              //   str_temp   =   new   SqlParameter();
              //   str_temp.ParameterName   =   "@str_temp ";
              //   str_temp.SqlDbType   =   SqlDbType.Char;
              //   str_temp.Size   =   10;