本文介绍了未能参数值从字符串到十进制转换?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这样一个存储过程:
ALTER PROCEDURE [DBO] [usp_CSR_UpdateDailyCustomerWithLCDHistory]
- 添加参数存储过程在这里
@person_id数字(18,0),
@last_contact_date日期时间,
@source为nvarchar(50),
@callLogId INT,
@createdBy为nvarchar(50)
AS
BEGIN ... END
在我的代码调用这个存储过程:
公共无效UpdateDailyCustomerWithLCDHistory(字符串来电显示,
INT callLogId,串csrName )
{
试
{
数据库DB = DatabaseFactory.CreateDatabase
(MarketingWriteConnectionString);
的DbCommand的DbCommand =
db.GetStoredProcCommand(usp_CSR_UpdateDailyCustomerWithLCDHistory);
dbCommand.CommandTimeout = AppSetting.Instance.GetCommandTimeout();
db.AddInParameter(的DbCommand,为person_id,DbType.Decimal,来电显示);
db.AddInParameter(的DbCommandlast_contact_date,DbType.Date,
DateTime.Now.ToShortDateString());
db.AddInParameter(的DbCommand,源,DbType.String,CSR);
db.AddInParameter(的DbCommand,callLogId,DbType.Int32,callLogId);
db.AddInParameter(的DbCommand,createdBy,DbType.String,csrName);
db.ExecuteNonQuery(的DbCommand);
}
}
这是我表的结构:
CREATE TABLE [DBO]。[tblDailyCustomerLastContactDateHistory(
[为person_id] [数字](18,0)NOT NULL,
[来源] [为nvarchar(50)NOT NULL,
[callLogId] [INT] NULL,
[createdBy] [为nvarchar(50)NULL,
[last_contact_date] [日期时间] NOT NULL,
在部署应用程序,我得到了错误
quite often, not all the time though. Can anybody tell me what could be wrong?
解决方案
public void UpdateDailyCustomerWithLCDHistory(string callerId, int callLogId, string csrName)
{
try
{
Database db = DatabaseFactory.CreateDatabase("MarketingWriteConnectionString");
DbCommand dbCommand = db.GetStoredProcCommand("usp_CSR_UpdateDailyCustomerWithLCDHistory");
dbCommand.CommandTimeout = AppSetting.Instance.GetCommandTimeout();
db.AddInParameter(dbCommand, "person_id", DbType.Decimal, callerId);
the callId is a string, you need convert it the decimal before you assign to the value.
you can use Decimal.TryParse() to convert string to Decimal number.http://msdn.microsoft.com/en-us/library/system.decimal.tryparse.aspx
这篇关于未能参数值从字符串到十进制转换?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!