N
Nuzzi
Hello All,
I have two pages that are very similar. One is working, one is not. Here
is the code for both:
Page 1 (Working):
protected void btn_update_Click(object sender, EventArgs e)
{
Int32 item_id = Convert.ToInt32(ViewState["item_id"]);
Int32 news_id = Convert.ToInt32(ViewState["news_id"]);
string sql = "UPDATE web_items SET item_title = @title, item_body
= @body, item_descriptor = @descriptor " +
"WHERE item_id = @item";
SqlConnection con = new SqlConnection(* My Connection String *);
SqlCommand id_cmd = new SqlCommand(sql, con);
id_cmd.Parameters.Add("@title", SqlDbType.NVarChar).Value =
tb_title.Text;
id_cmd.Parameters.Add("@body", SqlDbType.NText).Value =
fb_item.Text;
id_cmd.Parameters.Add("@descriptor", SqlDbType.NText).Value =
fb_descriptor.Text;
id_cmd.Parameters.Add("@item", SqlDbType.Int).Value = item_id;
con.Open();
Int32 count = id_cmd.ExecuteNonQuery();
con.Close();
if ( count > 0 )
{
// Step 2
id_cmd.Parameters.Clear();
id_cmd.CommandText = "UPDATE web_news SET news_category_id =
@cat_id, news_published = @publish, news_user_id = @user_id " +
"WHERE news_id = @news";
id_cmd.Parameters.Add("@cat_id", SqlDbType.Int).Value =
Convert.ToInt32(dd_cat.SelectedValue);
id_cmd.Parameters.Add("@publish", SqlDbType.Bit).Value =
cb_publish.Checked;
id_cmd.Parameters.Add("@user_id", SqlDbType.Int).Value =
Convert.ToInt32(dd_author.SelectedValue);
id_cmd.Parameters.Add("@news", SqlDbType.Int).Value = news_id;
con.Open();
count = id_cmd.ExecuteNonQuery();
con.Close();
if (count > 0)
Response.Redirect("news.aspx?status=updated");
else
litResult.Text = "An error has occurred, please see site
Administrator.";
}
else
litResult.Text = "An error has occurred, please see site
Administrator.";
}
Page 2 : (Not Working)
protected void btn_update_Click(object sender, EventArgs e)
{
Int32 item_id = Convert.ToInt32(ViewState["item_id"]);
Int32 product_id = Convert.ToInt32(ViewState["product_id"]);
string sql = "UPDATE web_items SET item_title = @title, item_body
= @body " +
"WHERE item_id = @item";
SqlConnection con = new SqlConnection(* My Connection String*);
SqlCommand id_cmd = new SqlCommand(sql, con);
id_cmd.Parameters.Add("@title", SqlDbType.NVarChar).Value =
tb_title.Text;
id_cmd.Parameters.Add("@body", SqlDbType.NText).Value =
fb_item.Text;
id_cmd.Parameters.Add("@item", SqlDbType.Int).Value = item_id;
con.Open();
Int32 count = id_cmd.ExecuteNonQuery();
con.Close();
if (count > 0)
{
// Step 2
id_cmd.Parameters.Clear();
id_cmd.CommandText = "UPDATE web_products SET product_name =
@name " +
"WHERE product_id = @product";
id_cmd.Parameters.Add("@name", SqlDbType.NVarChar).Value =
tb_title.Text;
id_cmd.Parameters.Add("@product", SqlDbType.Int).Value =
product_id;
con.Open();
count = id_cmd.ExecuteNonQuery();
con.Close();
if (count > 0)
Response.Redirect("products.aspx?status=updated");
else
litResult.Text = "An error has occurred, please see site
Administrator.";
}
else
litResult.Text = "An error has occurred, please see site
Administrator.";
}
The strange part about it not working is that it redirects to the
"Updated" page like both updates were successful, but the data is not
changing. I have checked the DB to confirm this.
Thank You in advance.
NUZZI
I have two pages that are very similar. One is working, one is not. Here
is the code for both:
Page 1 (Working):
protected void btn_update_Click(object sender, EventArgs e)
{
Int32 item_id = Convert.ToInt32(ViewState["item_id"]);
Int32 news_id = Convert.ToInt32(ViewState["news_id"]);
string sql = "UPDATE web_items SET item_title = @title, item_body
= @body, item_descriptor = @descriptor " +
"WHERE item_id = @item";
SqlConnection con = new SqlConnection(* My Connection String *);
SqlCommand id_cmd = new SqlCommand(sql, con);
id_cmd.Parameters.Add("@title", SqlDbType.NVarChar).Value =
tb_title.Text;
id_cmd.Parameters.Add("@body", SqlDbType.NText).Value =
fb_item.Text;
id_cmd.Parameters.Add("@descriptor", SqlDbType.NText).Value =
fb_descriptor.Text;
id_cmd.Parameters.Add("@item", SqlDbType.Int).Value = item_id;
con.Open();
Int32 count = id_cmd.ExecuteNonQuery();
con.Close();
if ( count > 0 )
{
// Step 2
id_cmd.Parameters.Clear();
id_cmd.CommandText = "UPDATE web_news SET news_category_id =
@cat_id, news_published = @publish, news_user_id = @user_id " +
"WHERE news_id = @news";
id_cmd.Parameters.Add("@cat_id", SqlDbType.Int).Value =
Convert.ToInt32(dd_cat.SelectedValue);
id_cmd.Parameters.Add("@publish", SqlDbType.Bit).Value =
cb_publish.Checked;
id_cmd.Parameters.Add("@user_id", SqlDbType.Int).Value =
Convert.ToInt32(dd_author.SelectedValue);
id_cmd.Parameters.Add("@news", SqlDbType.Int).Value = news_id;
con.Open();
count = id_cmd.ExecuteNonQuery();
con.Close();
if (count > 0)
Response.Redirect("news.aspx?status=updated");
else
litResult.Text = "An error has occurred, please see site
Administrator.";
}
else
litResult.Text = "An error has occurred, please see site
Administrator.";
}
Page 2 : (Not Working)
protected void btn_update_Click(object sender, EventArgs e)
{
Int32 item_id = Convert.ToInt32(ViewState["item_id"]);
Int32 product_id = Convert.ToInt32(ViewState["product_id"]);
string sql = "UPDATE web_items SET item_title = @title, item_body
= @body " +
"WHERE item_id = @item";
SqlConnection con = new SqlConnection(* My Connection String*);
SqlCommand id_cmd = new SqlCommand(sql, con);
id_cmd.Parameters.Add("@title", SqlDbType.NVarChar).Value =
tb_title.Text;
id_cmd.Parameters.Add("@body", SqlDbType.NText).Value =
fb_item.Text;
id_cmd.Parameters.Add("@item", SqlDbType.Int).Value = item_id;
con.Open();
Int32 count = id_cmd.ExecuteNonQuery();
con.Close();
if (count > 0)
{
// Step 2
id_cmd.Parameters.Clear();
id_cmd.CommandText = "UPDATE web_products SET product_name =
@name " +
"WHERE product_id = @product";
id_cmd.Parameters.Add("@name", SqlDbType.NVarChar).Value =
tb_title.Text;
id_cmd.Parameters.Add("@product", SqlDbType.Int).Value =
product_id;
con.Open();
count = id_cmd.ExecuteNonQuery();
con.Close();
if (count > 0)
Response.Redirect("products.aspx?status=updated");
else
litResult.Text = "An error has occurred, please see site
Administrator.";
}
else
litResult.Text = "An error has occurred, please see site
Administrator.";
}
The strange part about it not working is that it redirects to the
"Updated" page like both updates were successful, but the data is not
changing. I have checked the DB to confirm this.
Thank You in advance.
NUZZI