Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6944825
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:21:27+00:00 2026-05-27T13:21:27+00:00

When I run the stored procedure manually, it works fine. However, whenever I try

  • 0

When I run the stored procedure manually, it works fine. However, whenever I try to call it with my code below, nothing is updating. One thing I’ve noticed is that in my stored procedure, I change the “Modified Date” field to the current time/date and that IS updating; however, none of my other values are.

Here’s my method I’m using:

public void EditProduct(int productID, string productName, string productNumber, string productColor, string productSubcategory)
    {
        ConfigureDataAccess();
        myCommand = new SqlCommand("[dbo].[UpdateProductInfo]", myConnection);
        myCommand.CommandType = CommandType.StoredProcedure;
        myCommand.Parameters.AddWithValue("@ProductID", productID);
        myCommand.Parameters.AddWithValue("@ProductName", String.IsNullOrWhiteSpace(productName) ? (object)DBNull.Value : (object)productName);
        myCommand.Parameters.AddWithValue("@ProductNumber", String.IsNullOrWhiteSpace(productNumber) ? (object)DBNull.Value : (object)productNumber);
        myCommand.Parameters.AddWithValue("@ProductColor", String.IsNullOrWhiteSpace(productColor) ? (object)DBNull.Value : (object)productColor);
        myCommand.Parameters.AddWithValue("@ProductSubcategory", String.IsNullOrWhiteSpace(productSubcategory) ? (object)DBNull.Value : (object)productSubcategory);

        try
        {
            try
            {
                myConnection.Open();
                myCommand.ExecuteNonQuery();
            }
            catch (SqlException exception)
            {
                exception.Data.Add("cstring", myConfiguration);
                throw;
            }
            catch (InvalidOperationException ex)
            {
                ex.Data.Add("cStatus", myConnection.State);
                throw;
            }
        }
        finally
        {
            myConnection.Close();
        }

I don’t believe ConfigureDataAccess() is an issue because other methods are using it and they are running fine. Is there anything that immediately sticks out?

Edit: Here’s my stored procedure:

ALTER PROCEDURE [dbo].[UpdateProductInfo]

@ProductID as int,
@ProductName as varchar(50),
@ProductNumber as varchar(25),
@ProductColor as varchar(15),
@ProductSubcategory as varchar(50)

AS
BEGIN

SET NOCOUNT ON;

UPDATE P
SET P.Name = @ProductName, P.ProductNumber = @ProductNumber, P.Color = @ProductColor, P.ModifiedDate = GetDate(), 
P.ProductSubcategoryID = (SELECT PS.ProductSubcategoryID FROM Production.ProductSubcategory PS WHERE PS.Name = @ProductSubcategory)
FROM Production.Product as P
LEFT OUTER JOIN  Production.ProductSubcategory as PS ON P.ProductSubcategoryID = PS.ProductSubcategoryID
WHERE P.ProductID = @ProductID
END

Here’s my ConfigureDataAccess() method:

    private string myConfiguration;
    private SqlConnection myConnection;
    private SqlCommand myCommand;
    private SqlDataReader myReader;
    private List<Product> myProducts;

    public void ConfigureDataAccess()
    {
        myConfiguration = ConfigurationManager.ConnectionStrings["myConnection"].ConnectionString;
        myConnection = new SqlConnection(myConfiguration);
        myReader = null;
        myProducts = new List<Product>();
    }    
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T13:21:28+00:00Added an answer on May 27, 2026 at 1:21 pm

    I figured out the problem. I needed to include if (!IsPostBack) in my Page_Load event. I didn’t realize that when I was clicking the “Save” button on my webform that it was posting back and setting my textboxes (on which the parameters in the EditProduct() method are getting their values) back to their original values.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When I try to run a particular stored procedure on my MS SQL 2005
I need to run a stored procedure from a C# application. I use the
I have a button that when clicked will run a stored procedure on a
I would like to know how you would run a stored procedure from a
Well I have this MySQL stored procedure that I wrote and if I run
I've got a Stored Procedure in SQL Server 2005 and when I run it
I am trying to run a stored procedure with a while loop in it
I need to call two stored procedures in sequence via ODBC in PHP: #run
I'm trying to call a stored procedure (on a SQL 2005 server) from C#,
I have a number of stored procedures I call from code with ExecuteNonQuery .

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.