我一直试图将值为1的int传递给我的存储过程但是我一直得到“数据类型tinyint的算术溢出错误,值= -1。”的例外。 int的值是1,但异常表示-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
Image_name=@p_filename,
Active=-@p_Active,
Url=@p_url,
Alt_text=@p_alt_text
WHERE Image_id=@p_image_id
答案 0 :(得分:2)
在更新语句中调用@p_active之前,您有一个减号:
主动= - @ p_Active
可能是你的问题!
答案 1 :(得分:0)
在存储过程中,@ p_Active前面有一个负号,同时将值赋给Active。
Active=-@p_Active,