Hello,
I am trying to code the page_load event read a database table, if a column "Active" has a "1", then redirect to another page, otherwise, load the page normally,
My test page is as follows:
----------------
protected void Page_Load(object sender, EventArgs e)
{
getData();
}
private void getData()
{
// Create a connection
SqlConnection MsgEmergency = new SqlConnection(connectionString);
// Open the connection
MsgEmergency.Open();
// Create a String to hold the query.
string query = "SELECT Active FROM tbl_News WHERE Active=1";
// Create a SqlCommand object and pass the constructor the connection string and the query string.
SqlCommand queryCommand = new SqlCommand(query, MsgEmergency);
//SqlDataReader dr = queryCommand.ExecuteReader();
int results = (Int32)queryCommand.ExecuteScalar();
if (results != 1)
Response.Redirect("default_emergency.aspx");
else
Response.Redirect("default.aspx");
MsgEmergency.Close();
}
-----------------------------------
ANY help would be greatly appreciated.
{
// getData();
getWarning();
}
private void getWarning()
{
using(SqlConnection con = new SqlConnection(connectionSt
{
con.Open();
SqlCommand cmd = new SqlCommand("SELECT Active FROM tbl_News WHERE Active=1",con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
if (dt.Rows.Count > 0)
{
Response.Redirect("default
}
else
{
Response.Redirect("default
}
}
}