Click here to Skip to main content
15,895,084 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i loaded records from my database and fill my text boxes and i'm trying to update with the record in the text but not work.please help me

What I have tried:

protected void Update_Click(object sender, EventArgs e)
      {
          ccObject = new ConnectionClass();
          if (!IsPostBack)
          {

              try
              {
                  ccObject.Query(" uspUpdateProductInventory");
                  ccObject.cmd.Parameters.AddWithValue("@QuantityToAdd", TbxQtytoAdd.Text);
                  ccObject.cmd.Parameters.AddWithValue("@ProductCode", TbxProductCode.Text);

                  ccObject.ExcuteQuery();

                  string SuccessMessage = "INVENTORY UPDATE SUCCESSFUL";
                  ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('" + SuccessMessage + "');", true);
              }
              catch (Exception ex)
              {

                  throw ex;
              }
              finally
              {
                  ccObject.CloseConnection();

              }
          }




      }

-------------------- usp for update----------------------------------
ALTER PROCEDURE [dbo].[uspUpdateProductInventory]
	-- Add the parameters for the stored procedure here
	@QuantityToAdd int,
	@ProductCode varchar(50)
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	UPDATE Product.Inventory set QuantityAtStore = QuantityAtStore + @QuantityToAdd WHERE ProductCode=@ProductCode
END

the database table has
|id|ProductCode|QuantityAtStore|
| | | |
__--------------------------------------------------------------------------------
<div class="form-group">
                 <label for="productcode">Product Code</label>
                   <asp:TextBox ID="TbxProductCode" CssClass="form-control" runat="server" OnTextChanged="TbxProductCode_TextChanged" AutoPostBack="True"></asp:TextBox>
                            <asp:RequiredFieldValidator ID="RfvProductCode" runat="server" ErrorMessage="Enter Product Code" ForeColor="Red" ControlToValidate="TbxProductCode" Display="Dynamic" ></asp:RequiredFieldValidator>
               </div>
               <div class="form-group">
                 <label for="ProductName">Product Name</label>
                   <asp:TextBox ID="TbxProductName" CssClass="form-control" ReadOnly="true" runat="server"></asp:TextBox>
               </div>
                 <div class="form-group">
                 <label for="Quantity in store">Quantity in Store</label>
                   <asp:TextBox ID="TbxQtyinStore" CssClass="form-control" ReadOnly="true" runat="server"></asp:TextBox>
               </div>
               <div class="form-group">
                 <label for="quantity to add">Quantity to Add</label>
                   <asp:TextBox ID="TbxQtytoAdd" CssClass="form-control" runat="server"></asp:TextBox>
                   <asp:RequiredFieldValidator ID="RfvQuantityToAdd" runat="server" ErrorMessage="Enter Quantity To Add" ForeColor="Red" ControlToValidate="TbxQtytoAdd" Display="Dynamic" ></asp:RequiredFieldValidator>
                   <asp:CompareValidator ID="CvQuantityToAdd" runat="server" ErrorMessage="invalid Quantity" ControlToValidate="TbxQtytoAdd" Operator="DataTypeCheck" Type="Integer" Display="Dynamic" ForeColor="Red" ></asp:CompareValidator>
               </div>
Posted
Updated 13-Apr-18 5:41am
v2
Comments
F-ES Sitecore 13-Apr-18 11:20am    
"Doesn't work" means nothing, would you phone your mechanic and say "My car doesn't work, how do I fix it?"

It could be your SQL isn't running, you haven't told us if it is, or if you're getting an exception, so we don't know

Your SQL might be running but throwing an error, again you haven't said

Your SQL might be fine but maybe there is no such order with the given id, we don't know what id you are using and we don't know what is in your database so can't help there.

Maybe the issue is that you're putting string into a field that wants a number (QuantityToAdd) so need to convert that to an integer first.
Member 13543270 13-Apr-18 11:32am    
my sql is working fine
it throws no exception and the record not updating to
Member 13543270 13-Apr-18 12:01pm    
thanks it's working now

1 solution

Um.
C#
if (!IsPostBack)
{
So it's a button press that doesn't cause a postback? Are you sure about that?
 
Share this answer
 
Comments
Member 13543270 13-Apr-18 11:55am    
thanks, i had the perfect code but still wasn't running out off confusing i added the !ispostback thanks very much
OriginalGriff 13-Apr-18 12:01pm    
You're welcome!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900