SqlCommand Parameters

  • Thread starter Thread starter daveL
  • Start date Start date
D

daveL

What is wrong with the below code
SqlCommand oCmd = new SqlCommand();
oCmd.CommandText = "Select top 10 * from mydataabase..mytable where id =
@id"

oCmd.Parameters.Add("@id", SqlDbType.Int);
oCmd.Parameters[0].Value= 1301611;
oCmd.Connection = this.oConn;
SqlDataReader=oCmd.ExecuteReader()
//i get error must declare scalar variable @Id
 
try making the connection string and then try again running ur code
--
Harsh


daveL said:
Nevermind Fixed, Had a Typo

Dave

daveL said:
What is wrong with the below code
SqlCommand oCmd = new SqlCommand();
oCmd.CommandText = "Select top 10 * from mydataabase..mytable where id =
@id"

oCmd.Parameters.Add("@id", SqlDbType.Int);
oCmd.Parameters[0].Value= 1301611;
oCmd.Connection = this.oConn;
SqlDataReader=oCmd.ExecuteReader()
//i get error must declare scalar variable @Id
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top