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_Clic k(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.Paramete rs.Add("@title" , SqlDbType.NVarC har).Value =
tb_title.Text;
id_cmd.Paramete rs.Add("@body", SqlDbType.NText ).Value =
fb_item.Text;
id_cmd.Paramete rs.Add("@descri ptor", SqlDbType.NText ).Value =
fb_descriptor.T ext;
id_cmd.Paramete rs.Add("@item", SqlDbType.Int). Value = item_id;
con.Open();
Int32 count = id_cmd.ExecuteN onQuery();
con.Close();
if ( count 0 )
{
// Step 2
id_cmd.Paramete rs.Clear();
id_cmd.CommandT ext = "UPDATE web_news SET news_category_i d =
@cat_id, news_published = @publish, news_user_id = @user_id " +
"WHERE news_id = @news";
id_cmd.Paramete rs.Add("@cat_id ", SqlDbType.Int). Value =
Convert.ToInt32 (dd_cat.Selecte dValue);
id_cmd.Paramete rs.Add("@publis h", SqlDbType.Bit). Value =
cb_publish.Chec ked;
id_cmd.Paramete rs.Add("@user_i d", SqlDbType.Int). Value =
Convert.ToInt32 (dd_author.Sele ctedValue);
id_cmd.Paramete rs.Add("@news", SqlDbType.Int). Value = news_id;
con.Open();
count = id_cmd.ExecuteN onQuery();
con.Close();
if (count 0)
Response.Redire ct("news.aspx?s tatus=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_Clic k(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.Paramete rs.Add("@title" , SqlDbType.NVarC har).Value =
tb_title.Text;
id_cmd.Paramete rs.Add("@body", SqlDbType.NText ).Value =
fb_item.Text;
id_cmd.Paramete rs.Add("@item", SqlDbType.Int). Value = item_id;
con.Open();
Int32 count = id_cmd.ExecuteN onQuery();
con.Close();
if (count 0)
{
// Step 2
id_cmd.Paramete rs.Clear();
id_cmd.CommandT ext = "UPDATE web_products SET product_name =
@name " +
"WHERE product_id = @product";
id_cmd.Paramete rs.Add("@name", SqlDbType.NVarC har).Value =
tb_title.Text;
id_cmd.Paramete rs.Add("@produc t", SqlDbType.Int). Value =
product_id;
con.Open();
count = id_cmd.ExecuteN onQuery();
con.Close();
if (count 0)
Response.Redire ct("products.as px?status=updat ed");
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_Clic k(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.Paramete rs.Add("@title" , SqlDbType.NVarC har).Value =
tb_title.Text;
id_cmd.Paramete rs.Add("@body", SqlDbType.NText ).Value =
fb_item.Text;
id_cmd.Paramete rs.Add("@descri ptor", SqlDbType.NText ).Value =
fb_descriptor.T ext;
id_cmd.Paramete rs.Add("@item", SqlDbType.Int). Value = item_id;
con.Open();
Int32 count = id_cmd.ExecuteN onQuery();
con.Close();
if ( count 0 )
{
// Step 2
id_cmd.Paramete rs.Clear();
id_cmd.CommandT ext = "UPDATE web_news SET news_category_i d =
@cat_id, news_published = @publish, news_user_id = @user_id " +
"WHERE news_id = @news";
id_cmd.Paramete rs.Add("@cat_id ", SqlDbType.Int). Value =
Convert.ToInt32 (dd_cat.Selecte dValue);
id_cmd.Paramete rs.Add("@publis h", SqlDbType.Bit). Value =
cb_publish.Chec ked;
id_cmd.Paramete rs.Add("@user_i d", SqlDbType.Int). Value =
Convert.ToInt32 (dd_author.Sele ctedValue);
id_cmd.Paramete rs.Add("@news", SqlDbType.Int). Value = news_id;
con.Open();
count = id_cmd.ExecuteN onQuery();
con.Close();
if (count 0)
Response.Redire ct("news.aspx?s tatus=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_Clic k(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.Paramete rs.Add("@title" , SqlDbType.NVarC har).Value =
tb_title.Text;
id_cmd.Paramete rs.Add("@body", SqlDbType.NText ).Value =
fb_item.Text;
id_cmd.Paramete rs.Add("@item", SqlDbType.Int). Value = item_id;
con.Open();
Int32 count = id_cmd.ExecuteN onQuery();
con.Close();
if (count 0)
{
// Step 2
id_cmd.Paramete rs.Clear();
id_cmd.CommandT ext = "UPDATE web_products SET product_name =
@name " +
"WHERE product_id = @product";
id_cmd.Paramete rs.Add("@name", SqlDbType.NVarC har).Value =
tb_title.Text;
id_cmd.Paramete rs.Add("@produc t", SqlDbType.Int). Value =
product_id;
con.Open();
count = id_cmd.ExecuteN onQuery();
con.Close();
if (count 0)
Response.Redire ct("products.as px?status=updat ed");
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
Comment