Answered by:
Database not updating

Question
-
User336760158 posted
I cannot work out why the database is not up dating
If I manually insert 9999 it updates but not from the textbox
Any ideas would be appreciated
Here is the code
objCmd =new SqlCommand("UPDATE location SET IndustryCode2 = @IndustryCode WHERE location.LocationID = @LocID", objConn);
prm =new SqlParameter("@IndustryCode", SqlDbType.VarChar, 1000);
prm.Direction = ParameterDirection.Input;
prm.Value = TextBox1.Text;
// prm.Value = "9999";
objCmd.Parameters.Add(prm);
prm = new SqlParameter("@LocID", SqlDbType.VarChar, 50);
prm.Direction = ParameterDirection.Input;
prm.Value = Session["LocID"].ToString();
objCmd.Parameters.Add(prm);
objConn.Open();
objCmd.ExecuteNonQuery();
objConn.Close();
//TextBox1.Text = Elect5RB.SelectedItem.Value;
}
}
Thursday, December 17, 2015 6:01 AM
Answers
-
User-1078128378 posted
Hi Powderworks,
replace this line
objCmd =new SqlCommand("UPDATE location SET IndustryCode2 = @IndustryCode WHERE location.LocationID = @LocID", objConn);
with
objCmd =new SqlCommand("UPDATE location SET IndustryCode2 = @IndustryCode WHERE LocationID = @LocID", objConn);
and also check your Page_Load Event
Page Load should be like this
if(!Page.IsPostback)
{
//Your Code
}
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, December 17, 2015 6:05 AM
All replies
-
User-1078128378 posted
Hi Powderworks,
replace this line
objCmd =new SqlCommand("UPDATE location SET IndustryCode2 = @IndustryCode WHERE location.LocationID = @LocID", objConn);
with
objCmd =new SqlCommand("UPDATE location SET IndustryCode2 = @IndustryCode WHERE LocationID = @LocID", objConn);
and also check your Page_Load Event
Page Load should be like this
if(!Page.IsPostback)
{
//Your Code
}
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, December 17, 2015 6:05 AM -
User-1716253493 posted
Your code looks good, I agree with previous post.
Maybe you have set the textbox text from database in page_load event.
You should place it inside if(!IsPostBack) block
if(!IsPostBack) { TextBox1.Text = "123"; }
Thursday, December 17, 2015 6:33 AM -
User1724605321 posted
Hi powderworks,
For this kind of issues , i would suggest you could set breakpoints to page_load event and update function to check whether the textbox value is correct (or not reset) .Below link is how to navigate through code with the debugger in vs:
https://msdn.microsoft.com/en-us/library/y740d9d3.aspx .Best Regards,
Nan Yu
Thursday, December 17, 2015 7:05 AM -
User336760158 posted
Thanks you solved the ipostback was missingFriday, December 18, 2015 3:42 AM -
User-2046632488 posted
You should place it inside if(!IsPostBack) block
if(!IsPostBack) { TextBox1.Text = "123"; }
Friday, December 18, 2015 6:05 AM