In your SP, the sql statement is treating your table name as table variable.
Try something like this, include your WHERE clause,SELECT clause

DECLARE @tablename nvarchar(500)
DECLARE @retrieve nvarchar(2000)

SET @tablename = 'test'
SET @retrieve = 'SELECT * FROM ' + @tablename
EXEC (@retrieve)

Dynamic SQL
http://www.sommarskog.se/dynamic_sql.html

But the ideal way would be using command parameters and specifying command
type as Stored Procedure
http://www.codeproject.com/KB/cs/simplecodeasp.aspx

 On Tue, Aug 11, 2009 at 6:53 PM, Yogesh Dige <[email protected]> wrote:

>
> con = new SqlConnection(strConnectionString);
>            string strQry = "EXEC GetData " + strParameters;
>            command = new SqlCommand(strProcNm, con);
>            adapter = new SqlDataAdapter(command);
>
> i am using the above code for callin Stored Procecures i am passing
> the parameters as Table name, and a fields to the my general stored
> procedures. but it is giving the error that not finding the table name
> and it is asking the table name as " @sTablename".
>
> So please can any body help me for this.
> i want to use above method only.
>
> Thank you advance...
>

Reply via email to