Create WebService for Getting Details of Tables from Oracle Database in ASP.NET

Introduction

Check the given below code where developers can create a web method to get the Table Details from an Oracle Database.

[WebMethod]

public static List<string> GetTableName(string prefixText)

{

    List<string> result = new List<string>();

    try

    {

        String connString = ConfigurationManager.ConnectionStrings["OracleConnectionString"].ConnectionString;

        OracleConnection conn = new OracleConnection(connString);

        OracleCommand cmd = new OracleCommand();

        cmd.CommandText = "SELECT OBJECT_NAME FROM USER_OBJECTS WHERE OBJECT_TYPE='TABLE' AND OBJECT_NAME LIKE '" + prefixText.ToUpper() + "%'";

        cmd.Connection = conn;

        conn.Open();

        OracleDataReader reader = cmd.ExecuteReader();

        while (reader.Read())

        {

           result.Add(reader["OBJECT_NAME"].ToString());

        }

    }

    catch (Exception ex)

    {

        throw ex;

    }

    return result;

}

X

Build smarter apps with Machine Learning, Bots, Cognitive Services - Start free.

Start Learning Now