亚洲免费乱码视频,日韩 欧美 国产 动漫 一区,97在线观看免费视频播国产,中文字幕亚洲图片

      1. <legend id="ppnor"></legend>

      2. 
        
        <sup id="ppnor"><input id="ppnor"></input></sup>
        <s id="ppnor"></s>

        C#中MySQL語句帶參數(shù)的模糊匹配問題

        字號:

        用的是MySQL數(shù)據(jù)庫,但是當我用帶參數(shù)的sql語句進行模糊查詢時,發(fā)現(xiàn)MySQL沒有識別我的參數(shù)中的內容。經(jīng)過了多次實驗,終于找到了答案,拿出來和大家分享,不多說了,詳細如下:
            public DataTable GetUserList(string strParam1,string strParam2,string strParam3,string strParam4)
            {
            StringBuilder sqlContent = new StringBuilder();
            ArrayList paramList = new ArrayList();
            sqlContent.Append(" SELECT ");
            sqlContent.Append(" column1");
            sqlContent.Append(" ,column2");
            sqlContent.Append(" ,column3 ");
            sqlContent.Append(" ,column4 ");
            sqlContent.Append(" FROM ");
            sqlContent.Append(" tab_temp ");
            sqlContent.Append(" WHERE 1=1");
            // 判斷參數(shù)是否為空或""
            if (!String.IsNullOrEmpty(strParam1))
            {
            sqlContent.Append(" AND column1 LIKE @param1 ");
            // 添加參數(shù)
            paramList.Add(new MySqlParameter("@param1", "%" + strParam1+ "%"));
            }
            if (!String.IsNullOrEmpty(strParam2))
            {
            sqlContent.Append(" AND column2 LIKE @param2 ");
            paramList.Add(new MySqlParameter("@param2", "%" + strParam2 + "%"));
            }
            if (!String.IsNullOrEmpty(strParam3))
            {
            sqlContent.Append(" AND column3 LIKE @param3 ");
            paramList.Add(new MySqlParameter("@param3", "%" + strParam3+ "%"));
            }
            if (!String.IsNullOrEmpty(strParam4))
            {
            sqlContent.Append(" AND column4 LIKE @param4 ");
            paramList.Add(new MySqlParameter("@param4", "%" + strParam4+ "%"));
            }
            try
            {
            // 獲取DB鏈接
            dbConn.getConnection();
            objDT = new DataTable();
            // 調用DBUtil中查詢方法
            objDT = dbConn.executeQuery(sqlContent.ToString(), paramList);
            }
            catch (Exception e)
            {
            throw e;
            }
            finally
            {
            // 關閉DB鏈接
            dbConn.closeConnection();
            }
            return objDT;
            }
            正確的寫法:
            sqlContent.Append(" AND column1 LIKE @param1 ");
            // 添加參數(shù)
            paramList.Add(new MySqlParameter("@param1", "%" + strParam1+ "%"));
            錯誤的寫法:
            sqlContent.Append(" AND column1 LIKE '%@param1%' ");
            // 添加參數(shù)
            paramList.Add(new MySqlParameter("@param1", strParam1));