asp.net - SQL Query not inputting value of my variable -


i'm having trouble writing query using variables. here's code

dim bondnumber string = "69836"  dim passwordcheck string = "declare @investor varchar(10),  @thepassword varchar(20), @linkedserver2 varchar(25), @sql varchar(1000) " passwordcheck += "select @investor = '" & bondnumber & "',  @linkedserver2 = 'binfodev', "passwordcheck += "@sql = 'select * ' +  @linkedserver2 + ' bondno = ''@investor'' ' exec(@sql)" 

it doesn't seem passing variables in query , i'm not sure i'm going wrong

any ideas?

what problem seeing specifically? more info help.

what can tell, you're code translates long line of sql (substituting '69836' bondnumber)

declare @investor varchar(10), @thepassword varchar(20), @linkedserver2 varchar(25), @sql varchar(1000) select @investor = '69836', @linkedserver2 = 'binfodev', @sql = 'select * ' + @linkedserver2 + ' bondno = ''@investor'' ' exec(@sql) 

i'll bet if execute in query window fail. try adding ; @ end of each logical statement.

have considered making code stored procedure , passing params this? code pretty hazardous (sql injection), hard read, , bit ugly in general.

sample stored procedure code:

create procedure dbo.usp_mystoredprocedure        @param1 int = null  select * mytable col1 = @param1 

Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

aspxgridview - Devexpress grid - header filter does not work if column is initially hidden -

c# - How to execute a particular part of code asynchronously in a class -