Asp. NET operation of Oracle database fuzzy query

Source: Internet
Author: User
Tags oracleconnection

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.