3

私はこのようなストアドプロシージャを持っています:

ALTER PROCEDURE [dbo].[usp_CSR_UpdateDailyCustomerWithLCDHistory]
    -- Add the parameters for the stored procedure here
    @person_id numeric(18, 0),
    @last_contact_date datetime,
    @source nvarchar(50),
    @callLogId int,
    @createdBy nvarchar(50)
AS
BEGIN...END

私のコードでは、このストアドプロシージャを呼び出します。

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);
        db.AddInParameter(dbCommand, "last_contact_date", DbType.Date,
            DateTime.Now.ToShortDateString());
        db.AddInParameter(dbCommand, "source", 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] [numeric](18, 0) NOT NULL,
    [source] [nvarchar](50) NOT NULL,
    [callLogId] [int] NULL,
    [createdBy] [nvarchar](50) NULL,
    [last_contact_date] [datetime] NOT NULL,

アプリケーションをデプロイした後、エラーが発生しました

パラメータ値を文字列から10進数に変換できませんでした

ただし、常にではありません。誰かが私に何が間違っている可能性があるか教えてもらえますか?

4

2 に答える 2

2
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);

callId は文字列です。値を割り当てる前に、10 進数に変換する必要があります。

Decimal.TryParse() を使用して文字列を 10 進数に変換できます。 http://msdn.microsoft.com/en-us/library/system.decimal.tryparse.aspx

于 2012-10-19T20:50:03.773 に答える
0

数値識別子が必要な場合は、(10 進数) フィールドINTの代わりに Id にを使用することをお勧めします。NUMERIC1.2、1.3 などの ID を持っている場合を除きます。

また、ご覧くださいAddWithValue- .NET コードで型を指定する必要はありません。フレームワークがそれを処理します。

最後に、callerIdが一致するタイプでない場合は、変更するか、少なくとも変換する必要があります。

于 2012-10-19T20:49:03.033 に答える