我有一個更新一些記錄的過程。當我執行它時,出現以下異常如何解決「字符串或二進制數據將被截斷。 r n聲明已終止。」錯誤?
「字符串或二進制數據將被截斷。\ r \ n語句已終止。」
當參數長度大於變量長度時,我可以發現這種情況。我再次檢查改變大小。但沒有奏效。再次發生同樣的異常。我該如何解決這個問題?請幫助
這裏是我的更新代碼
bool isFinished = dba.update(desingnation, title, initials, surname, fullname, callingName, civilSatatus, natinality, nic, birthday, passport,
hometp, mobiletp, province, district, division, electorate, gramaNiladhari, takafull, p_city,
c_city, p_hno, c_hno, tokens_P, tokens_C, previousEmployeements, bank, branch, type, account, gender, educatinalQ, languageE, languageS, languageT, empNo, appNo);
if (isFinished)
{
WebMsgBox.Show("Successfully Inserted!");
}
else
{
WebMsgBox.Show("Some Errors Occured");
}
}
else
{
WebMsgBox.Show("Some feilds are not valid");
}
}
}
這是通過存儲過程的參數
try
{
using (SqlCommand cmd = new SqlCommand())
{
cmd.CommandType = CommandType.Text;
cmd.CommandType = CommandType.StoredProcedure;
cmd.Connection = connection;
cmd.CommandTimeout = 0;
cmd.Transaction = transactions;
/*=======================Update employee details================================*/
cmd.CommandText = "update_HS_HR_EMPLOYEE_AADM";
cmd.Parameters.Add("@appNo", SqlDbType.Int).Value = appNo;
cmd.Parameters.Add("@CALLING_NAME", SqlDbType.VarChar).Value = callingName;
cmd.Parameters.Add("@INITIALS", SqlDbType.VarChar).Value = initials;
cmd.Parameters.Add("@SURNAME", SqlDbType.VarChar).Value = surname;
cmd.Parameters.Add("@TITLE", SqlDbType.VarChar).Value = title;
cmd.Parameters.Add("@NAME", SqlDbType.VarChar).Value = fullname;
cmd.Parameters.Add("@FULLNAME", SqlDbType.VarChar).Value = fullname + " " + surname;
cmd.Parameters.Add("@NIC", SqlDbType.VarChar).Value = nic;
cmd.Parameters.Add("@BDY", SqlDbType.VarChar).Value = birthday;
cmd.Parameters.Add("@GENDER", SqlDbType.VarChar).Value = gender;
cmd.Parameters.Add("@NATIONALITY", SqlDbType.VarChar).Value = natinality;
cmd.Parameters.Add("@CIVILSTATUS", SqlDbType.VarChar).Value = civilSatatus;
cmd.Parameters.Add("@DESIGNATION", SqlDbType.VarChar).Value = desingnation;
cmd.Parameters.Add("@P_ADD1", SqlDbType.VarChar).Value = p_hno;
cmd.Parameters.Add("@P_ADD2", SqlDbType.VarChar).Value = tokens_P[0];
if (tokens_P.Length > 1)
cmd.Parameters.Add("@P_ADD3", SqlDbType.VarChar).Value = tokens_P[1];
else
cmd.Parameters.Add("@P_ADD3", SqlDbType.VarChar).Value = "";
cmd.Parameters.Add("@P_CITY", SqlDbType.VarChar).Value = p_city;
cmd.Parameters.Add("@TP_HOME", SqlDbType.VarChar).Value = hometp;
cmd.Parameters.Add("@TP_MOBILE", SqlDbType.VarChar).Value = mobiletp;
cmd.Parameters.Add("@PROVINCE", SqlDbType.VarChar).Value = province;
cmd.Parameters.Add("@DISTRICT", SqlDbType.VarChar).Value = district;
cmd.Parameters.Add("@C_ADD1", SqlDbType.VarChar).Value = c_hno;
cmd.Parameters.Add("@C_ADD2", SqlDbType.VarChar).Value = tokens_C[0];
cmd.Parameters.Add("@PER_GNDIV_CODE", SqlDbType.VarChar).Value = gramaNiladhari;
cmd.Parameters.Add("@PER_DSDIV_CODE", SqlDbType.VarChar).Value = division;
cmd.Parameters.Add("@TAKAFUL", SqlDbType.VarChar).Value = takafull;
cmd.Parameters.Add("@PASSPORT_NO", SqlDbType.VarChar).Value = passport;
if (tokens_C.Length > 1)
cmd.Parameters.Add("@C_ADD3", SqlDbType.VarChar).Value = tokens_C[1];
else
cmd.Parameters.Add("@C_ADD3", SqlDbType.VarChar).Value = "";
cmd.Parameters.Add("@C_CITY", SqlDbType.VarChar).Value = c_city;
cmd.Parameters.Add("@ELECTORATE", SqlDbType.VarChar).Value = electorate;
//int appNO = int.Parse((cmd.ExecuteScalar().ToString()));
cmd.ExecuteNonQuery();
cmd.Parameters.Clear();
}
}
代碼這是存儲過程
ALTER PROCEDURE [dbo].[update_HS_HR_EMPLOYEE_AADM]
@appNo Int,
@CALLING_NAME VARCHAR(50),
@INITIALS VARCHAR(50),
@SURNAME VARCHAR(50),
@TITLE VARCHAR(50),
@NAME VARCHAR(50),
@FULLNAME VARCHAR(100),
@NIC VARCHAR(15),
@BDY VARCHAR(50),
@GENDER CHAR(1),
@NATIONALITY VARCHAR(50),
@CIVILSTATUS VARCHAR(50),
@DESIGNATION VARCHAR(50),
@P_ADD1 VARCHAR(50),
@P_ADD2 VARCHAR(50),
@P_ADD3 VARCHAR(50),
@P_CITY VARCHAR(50),
@TP_HOME VARCHAR(50),
@TP_MOBILE VARCHAR(50),
@PROVINCE VARCHAR(50),
@DISTRICT VARCHAR(50),
@C_ADD1 VARCHAR(50),
@C_ADD2 VARCHAR(50),
@C_ADD3 VARCHAR(50),
@C_CITY VARCHAR(50),
@ELECTORATE VARCHAR(50),
@PER_GNDIV_CODE VARCHAR(50),
@PER_DSDIV_CODE VARCHAR(50),
@TAKAFUL VARCHAR(50),
@PASSPORT_NO VARCHAR(50)
AS
BEGIN
update [HS_HR_EMPLOYEE_AADM]
SET
[EMP_CALLING_NAME][email protected]_NAME
,[EMP_MIDDLE_INI][email protected]
,[EMP_SURNAME][email protected]
,[EMP_TITLE][email protected]
,[EMP_NAMES_BY_INI][email protected]
,[EMP_FULLNAME][email protected]
,[EMP_NIC_NO][email protected]
,[EMP_BIRTHDAY][email protected]
,[EMP_GENDER][email protected]
,[NAT_CODE][email protected]
,[EMP_MARITAL_STATUS][email protected]
,[EMP_DATE_JOINED]=GETDATE()
,[EMP_CONFIRM_FLG]=0
,[CT_CODE]='000008'
,[DSG_CODE][email protected]
,[CAT_CODE]='000001'
,[EMP_PER_ADDRESS1][email protected]_ADD1
,[EMP_PER_ADDRESS2][email protected]_ADD2
,[EMP_PER_ADDRESS3][email protected]_ADD3
,[EMP_PER_CITY][email protected]_CITY
,[EMP_PER_TELEPHONE][email protected]_HOME
,[EMP_PER_MOBILE][email protected]_MOBILE
,[EMP_PER_PROVINCE_CODE][email protected]
,[EMP_PER_DISTRICT_CODE][email protected]
,[EMP_TEM_ADDRESS1][email protected]_ADD1
,[EMP_TEM_ADDRESS2][email protected]_ADD2
,[EMP_PER_ELECTORATE_CODE][email protected]
,[EMP_TEM_ADDRESS3][email protected]_ADD3
,[EMP_TEM_CITY][email protected]_CITY
,[EMP_PER_GNDIV_CODE][email protected]_GNDIV_CODE
,[EMP_PER_DSDIV_CODE][email protected]_DSDIV_CODE
,[EMP_PASSPORT_NO][email protected]
,[EMP_TAK][email protected]_NO
where App_no = @appNo
END
你能否請刪除不相關的代碼 –
@非幸運我已經刪除了一些代碼,從文本框和所有的數據。請看看 – Mike