0

I have been trying to pass an int with the value of 1 to my stored procedure but I keep getting an exception of "Arithmetic overflow error for data type tinyint, value = -1." The Value of the int is 1 but the exception says its -1 which I dont understand why. Anyway I have posted the code below. I am probably missing something obvious.

.net Code

protected void btnUpdate_Click(object sender, EventArgs e)
    {
        string result = "";
        string currentFileName = (string)(Session["FileName"]);
        string FileName = txtUploadStatus.Text;
        string sSQL = "usp_imageloader_update";
        int ImgID = (int)(Session["ImgID"]);

        using (SqlConnection dbConnection = new SqlConnection(CKS_app_settings.sql_conn_string_db))
        {
            // SqlTransaction tn=null;   
            try
            {
                dbConnection.Open();
                //start Transaction
                // tn = dbConnection.BeginTransaction();
                SqlCommand command = new SqlCommand(sSQL, dbConnection);
                //command.Transaction = tn;
                command.CommandText = sSQL;
                command.CommandType = CommandType.StoredProcedure;
                command.CommandTimeout = 1024;
int Active = 0;

                if (chkActive.Checked == true)
                {
                    Active = 1;
                }
                else
                {

                }

                if (currentFileName != FileName)
                {
                    // Split entire file path to grab filename
                    string[] split = txtUploadStatus.Text.Split(new char[] { '\\' });
                    FileName = split[06];
                }
                else
                {
                    FileName = txtUploadStatus.Text;
                }

                command.Parameters.AddWithValue("@p_image_id", ImgID);
                command.Parameters.AddWithValue("@p_filename", FileName);
                command.Parameters.AddWithValue("@p_Active", Active);
                command.Parameters.AddWithValue("@p_url", txtUrl.Text);
                command.Parameters.AddWithValue("@p_Title", txtImgTitle.Text);
                command.Parameters.AddWithValue("@p_alt_text", txtAlt.Text);
                int rowsAffected = command.ExecuteNonQuery();
            }
            catch (SqlException ex)
            {
               // throw ex;

                //If it failed for whatever reason, rollback the //transaction
                //tn.Rollback();                          
                //No need to throw because we are at a top level call and //nothing is handling exceptions
                result = ex.InnerException.Message;
            }

Stored Procedure

USE [smsdb_test_griffin2]
GO
/****** Object:  StoredProcedure [dbo].[usp_imageloader_update]    Script Date: 01/09/2012    08:52:01 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER    procedure [dbo].[usp_imageloader_update]
@p_image_id INT,
@p_filename VARCHAR(100),
@p_Active TINYINT,
@p_url  VARCHAR(255),
@p_Title VARCHAR(100),
@p_alt_text VARCHAR(255)
as 

UPDATE Image_Library_UK 
SET  
Image_name=@p_filename,
Active=-@p_Active,
Url=@p_url,
Alt_text=@p_alt_text 

WHERE Image_id=@p_image_id

2 Answers 2

2

You have a minus sign just before your call to @p_active in the update statement:

Active=-@p_Active

Probably your problem!

Sign up to request clarification or add additional context in comments.

Comments

0

In your stored procedure there is a negative symbol before @p_Active while assigning the value to Active.

Active=-@p_Active,

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.