.Net SqlProcedure Help.
Jan 17, 2008
I am getting a Must declare the table variable "@TableName" exception on this method and Im not sure why.
This is my commandText before I insert my parameters.
Code Block
Dim historyRecordCommand As String = "SELECT * FROM @TableName WHERE dbo.GetPrimaryKeyColumnName(@TableName)" & _
" = CONVERT(VARCHAR, @Key) AND HistoryRecordCreateDate BETWEEN" & _
" CONVERT(VARCHAR, @StartTime, 21) AND CONVERT(VARCHAR, @EndTime, 21)"
Code Block
Dim historyRecordSqlCommand As SqlCommand = connection.CreateCommand
historyRecordSqlCommand.CommandText = historyRecordCommand
historyRecordSqlCommand.Parameters.AddWithValue("@TableName", rowAccessionSystemLogDetail.TableName)
historyRecordSqlCommand.Parameters.AddWithValue("@Key", rowAccessionSystemLogDetail.TablePrimaryKeyValue)
historyRecordSqlCommand.Parameters.AddWithValue("@StartTime", rowAccessionSystemLogs.StartTime)
historyRecordSqlCommand.Parameters.AddWithValue("@EndTime", rowAccessionSystemLogs.EndTime)
Dim historyRowSqlReader As SqlDataReader = historyRecordSqlCommand.ExecuteReader(CommandBehavior.SingleRow)
I only expect to get 1 row back and I have checked all my values and they are fine also.
Anyone have any ideas?
Thanks