I have some SQL code that needs to be executed if a certain View exists in a database. How would I go about checking if the View exists?
EDIT: The DBMS being used is Mic
To expand on Kevin's answer.
private bool CustomViewExists(string viewName)
{
using (SalesPad.Data.DataConnection dc = yourconnection)
{
System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand(String.Format(@"IF EXISTS(select * FROM sys.views where name = '{0}')
Select 1
else
Select 0", viewName));
cmd.CommandType = CommandType.Text;
return Convert.ToBoolean(dc.ExecuteScalar(cmd));
}
}