【发布时间】:2014-04-02 11:57:07
【问题描述】:
目标:根据来自 .aspx.vb 代码的传入值更改正在更新的字段
问题:我相信上述 Aim 有效,但是我在 PropertyID(它是字母数字)上遇到错误,因为它说 Invalid column name '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+ '''')
【问题讨论】:
-
尝试将执行更改为打印并手动运行存储过程,并从会话中传递值。然后你会看到它要执行的语句。
-
找到并编辑了反映的代码。
标签: sql vb.net stored-procedures