C# code to check the table is exists in the oracle database

//C# code to check the table is exists in the oracle database



try
{

DataSet dataSet = new DataSet();
string connstr = "provider=MSDAORA.1;User ID=scott;Data
Source=<server>/<database>;Password=tiger;";
string query = "SELECT * FROM USER_TAB_COLUMNS WHERE
TABLE_NAME='CUSTOMER'";

using (OleDbConnection connection = new OleDbConnection(connstr))
{

connection.Open();

using (OleDbDataAdapter adapter = new OleDbDataAdapter(query,
connection))
{
adapter.Fill(dataSet, "CUSTOMER");
}

}

if (dataSet.Tables[0].Rows.Count > 0)
{
Trace.Write("Table exists in database");
}
else
{
Trace.Write("Table does not exists in database");
}

}
catch (Exception ex)
{
throw ex;
}


Comments

Author: Siva Prasad25 Mar 2012 Member Level: Gold   Points : 0

Nice code.Its working fine.

Guest Author: Gump18 Sep 2013

That's really thinking out of the box. Thanks!



  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: