2012-01-09 44 views
0

我一直試圖傳遞一個int值爲1到我的存儲過程,但我總是得到一個異常「數據類型tinyint的算術溢出錯誤,值= -1。「 int的值是1,但例外說明它的-1,我不明白爲什麼。無論如何,我已經發布了下面的代碼。我可能錯過了一些明顯的東西。SqlException:數據類型tinyint,值= -1的算術溢出錯誤

.NET代碼

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; 
      } 

存儲過程

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 
[email protected]_filename, 
[email protected]_Active, 
[email protected]_url, 
[email protected]_alt_text 

WHERE [email protected]_image_id 

回答

2

你有一個減號只是呼叫之前,在update語句@p_active:

活動= - @ p_Active

可能是你的問題!

+0

哇,我覺得有點傻,即固定它。謝謝! – 2012-01-09 12:35:37

+0

不用擔心,輕鬆完成:) – Timbo 2012-01-09 12:48:28

0

在您的存儲過程中,在將值分配給活動時,@p_Active之前有一個負號。

[email protected]_Active,

相關問題