Hi,
in the below code i am checking whether the database exists or not.if it exists it returns boolean value true or else false.But it gives me strange errors i.e. "Not All Code Paths Return A Value".I need some suggestions.
protected Boolean check_database(String dbname)
{ //Begining of 'check_database()' method.
try
{
con.Open();
SqlCommand cmd = new SqlCommand("checkDB_SP", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@db_name", dbname);
da = new SqlDataAdapter(cmd);
da.Fill(ds);
Boolean result;
if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
{
txt_result.Text = Convert.ToString(ds.Tables[0].Rows[0][0]);
int count = Convert.ToInt32(ds.Tables[0].Rows[0][0]);
if (count == 1)
{
Response.Write("<Script language='javascript' type='text/javascript'>alert('DataBase Exists!')</Script>");
//return true;
result = true;
break;
}
else
{
Response.Write("<Script language='javascript' type='text/javascript'>alert('DataBase Doesn't Exists!')</Script>");
txt_dbname.Text = "";
txt_dbname.Focus();
//return false;
result = false;
break;
}
return result;
}
else
{
lbl_msg.Text = "No Result In The DataSet!";
return false;
}
}
catch (Exception excp)
{
lbl_msg.Text = excp.Message.ToString();
}
finally
{
con.Close();
}
} //End of 'check_database()' method.