Sql 存储过程字段变量

Sql 存储过程字段变量,sql,vb.net,stored-procedures,Sql,Vb.net,Stored Procedures,目标:根据.aspx.vb代码中的传入值更改正在更新的字段 问题:我相信上述目标是可行的,但是我在PropertyID(字母数字)上遇到了一个错误,因为它显示无效的列名“S7753”。在本例中,我正在更新PropertyID S7753 .aspx.vb代码: command.CommandText = "spActionUpdateOldestDate" command.CommandType = CommandType.StoredProcedure Dim

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

问题:我相信上述目标是可行的,但是我在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+ '''')

在添加参数之前添加此行

 SqlCommandBuilder.DeriveParameters(command)

答案在顶部,这是PropertyID字符串的语法

尝试将execute更改为print,并手动运行存储过程,将值从会话传递给。然后,您将看到它将要执行的语句。找到并编辑了要反映的代码。如果我添加SqlCommandBuilder.DeriveParameters(命令),我会得到“过程或函数SpactionUpdateLDestDate指定的参数太多。”