Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

using SqlDataReader

Status
Not open for further replies.

nnmmss72

Programmer
May 14, 2006
110
0
0
IR
i have using a SqlDataReader to fill the repeater with this function , it works fine

String SelCmd="Select * from TblFRProduct order by Prod_id";
SqlCommand myCommand=new SqlCommand(SelCmd,myConnection);
myCommand.Connection.Open();
SqlDataReader dr= myCommand.ExecuteReader();
Repeater1.DataSource=dr;
Repeater1.DataBind();
myCommand.Connection.Close();


after that i have decided to use the SqlDataReader which was opened and get another record from database ,so i did so

String SelCmd="Select * from TblFRProduct order by Prod_id";
SqlCommand myCommand=new SqlCommand(SelCmd,myConnection);
myCommand.Connection.Open();
SqlDataReader dr= myCommand.ExecuteReader();
Repeater1.DataSource=dr;
Repeater1.DataBind();
dr.Close();

SelCmd="Select * from TblFRProduct prod_id=@id";
myCommand.CommandText=SelCmd;
myCommand.Parameters.Add(new SqlParameter("@id",SqlDbType.Int));
myCommand.Parameters["@id"].Value=System.Convert.ToInt32(MinProd_Id,10);
dr= myCommand.ExecuteReader();
LblProduct.Text=dr["description"].ToString();
myCommand.Connection.Close();

but i get this error
Incorrect syntax near '='.
the red line is that on dr= myCommand.ExecuteReader();
i am sure that parameters["@id"] is filled correctly. but it seems i can not use the SqlDataReader that i have used before. how can i do that?
 
You have no WHERE clause in your SQL Statement


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
yes my mistake. and also i have not used dr.Read();

anyway thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top