Asp. NET operation of Oracle database fuzzy query
ASP. NET MVC uses Oraclehelper helper classes to operate Oracle database
1 //Connection string connecting to Oracle database2String connectionString = @"Data source= (description= (address_list= (address= (PROTOCOL=TCP)3 (Host=localhost) (port=1521))) (Connect_data= (SERVICE_NAME=TESTDB)));4 User Id=developer; Password=developer ";5 6 ///<summary>7 ///Product Search page conditions: Based on the product name fuzzy query8 ///</summary>9 ///<returns></returns>Ten PublicActionResult Product (string proname) One { A /*law one, direct use like fuzzy query - String sql = "SELECT * from product where chvproname like '% ' | | Upper (:proname) | | '% '; - */ the //method Two, using Concat function query -String sql ="SELECT * from product where chvproname like Concat (concat ('% ', Upper (:P roname)), '% ')"; - -Viewbag.name =Proname; + //using the Oraclehelper helper class -DataSet ds =Oraclehelper.executedataset (connectionString, CommandType.Text, SQL, + NewOracleParameter (":P roname", Oracletype.nvarchar) {Value =proname}); A returnView (ds. Tables[0]); at}
I. ASP. NET Web Direct operation Oracle Database
Connection string connecting to Oracle database
String connectionString = @"Data source= (description= (address_list= (address=)
(Host=localhost) (port=1521))) (Connect_data= (SERVICE_NAME=TESTDB)));
User Id=developer; Password=developer ";
ProtectedvoidButton1_Click (Objectsender, EventArgs e) {String Proname= This. TxtProName.Text.Trim (); /*law one, direct use like fuzzy query string sql = "SELECT * from product where chvproname like '% ' | | Upper (:p roname) | | ' %‘"; */ //method Two, using Concat function queryString sql ="SELECT * from product where chvproname like Concat (concat ('% ', Upper (:p roname)), '% ')"; OracleConnection Connection=NewOracleConnection (connectionString); OracleCommand cmd=Neworaclecommand (SQL, connection); Cmd. Parameters.Add (NewOracleParameter (":p roname", proname) {OracleType =Oracletype.nvarchar}); OracleDataAdapter Adapter=NewOracleDataAdapter (CMD); DataSet DS=NewDataSet (); Adapter. Fill (DS); This. Gvpro.datasource = ds. Tables[0]. DefaultView; This. Gvpro.databind (); }
Description
In doing this example, because it is just contact with Oracle, so many statements and methods have been stuck in the MSSQLServer, so the first time to write a fuzzy query like statement when it actually put "| |" Written "+", but also debugging several times, and later was pointed out by the classmate was he laughed long time!
Oh, about the link between the characters in Oracle I guess I can't forget this life:
links between characters in Oracle with "| |" and the function concat (), not "+";
Asp. NET operation of Oracle database fuzzy query