存储过程字段变量

时间:2014-04-02 11:57:07

标签: sql vb.net stored-procedures

目标:根据.aspx.vb代码中的传入值更改要更新的字段

问题:我相信上面的Aim有效,但我在PropertyID(字母数字)上收到错误,因为它说无效的列名' S7753' 我正在更新PropertyID S7753。

.aspx.vb代码:

command.CommandText = "spActionUpdateOldestDate"
        command.CommandType = CommandType.StoredProcedure

        Dim vCheck As String = Session.Item("PropertyID").ToString & "-" & Session.Item("SafeGuardingDate").ToString & "-" & Session.Item("ActionsFieldName").ToString

        command.Parameters.AddWithValue("@PropertyID", Session.Item("PropertyID").ToString)
        command.Parameters.AddWithValue("@SafeGuardingDate", Session.Item("SafeGuardingDate").ToString)
        command.Parameters.AddWithValue("@ActionsFieldName", Session.Item("ActionsFieldName").ToString)

        command.ExecuteNonQuery()

        command.Parameters.Clear()

存储过程

    USE [DB]

GO
/****** Object:  StoredProcedure [dbo].[spActionUpdateOldestDate]    Script Date: 04/02/2014 14:24:09 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[spActionUpdateOldestDate] 

-- spActionUpdateOldestDate '1234','date','field'
    -- Add the parameters for the stored procedure here
            @PropertyID nvarchar(50)            
            ,@SafeGuardingDate nvarchar(MAX) 
             ,@ActionsFieldName varchar(MAX)

AS
BEGIN

-- add selection for courseID etc.. here

-- print 'UPDATE [TblActionsOldest] SET ' + @ActionsFieldName + ' = ''' + @SafeGuardingDate + ''' WHERE PropertyID = ''' + @PropertyID+ ''''
Execute ('UPDATE [TblActionsOldest] SET ' + @ActionsFieldName + ' = ''' + @SafeGuardingDate + ''' WHERE PropertyID = ''' + @PropertyID+ '''')

2 个答案:

答案 0 :(得分:1)

在添加参数

之前添加此行
 SqlCommandBuilder.DeriveParameters(command)

答案 1 :(得分:0)

在顶部回答,它是PropertyID字符串的语法。