Hi to all,
I want to execute same query atleast 5 times with different options.
so I execute datareader in while loop.
let considetr opt1 is my variable name passing to command.
when while loop in second iteration then it gives me error that

"The variable name '@opt1' has already been declared. Variable names must be unique within a query batch or stored procedure."

what is solution?

or may I write any code that gives me same result..?
I just want to fetch a column value for 5 different options given by user. In short 5 SELECT statement in single statement"

please reply!

Why don't you post the code where you are using the data reader? On the first iteration you need to add the "@opt1" variable to the SqlCommand, and on subsequent iterations you need to .Clear() the parameters, and re-add "@opt1"

You could also reference the parameter by name to change the value.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.