I have been using the following code to check if a particular row, column, table etc is present in the SQL Server database. I would like to know if there is a more efficient way to do this.
Note1: I am particularly trying to eliminate using the dataTable dt_local.
Note2: I am using C#, WinForms, VS-2015 and SQL Server 2008 R2 Express.
internal static bool MaujoodHaiKya(string queryLe)
{
//This function has been created to check
//if a particular row, column, table etc exists
//and to return true or false accordingly
try
{
DataTable dt_local = new DataTable();
string[] connString = System.IO.File.ReadAllLines(Application.StartupPath + "\\MM.ini");
using (SqlConnection conn = new SqlConnection(connString[1]))
{
SqlCommand cmd = new SqlCommand(queryLe, conn);
SqlDataAdapter adapter = new SqlDataAdapter();
conn.Open();
adapter.SelectCommand = cmd;
adapter.Fill(dt_local);
}
return (true); //Column exists
}
catch
{
return (false); //Column does not exist
}
}