Click here to Skip to main content
15,888,027 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello, the following code exits at the line:

var reader = getBrandsViaSupplier.ExecuteReader();

The query works fine and returns what I expect, and the format of the code is identical to about 50 other methods that all work as expected.

Why does this happen, and how do I track this kind of behavior?

C#
public static List<Brand> GetBrandsViaSupplier(int supplier)
 {
     var sqlConn = ConnectionFactory.CreateConnection();
     var getBrandsViaSupplier = new SqlCommand(
         "SELECT tblBrands.fldId, tblBrands.fldDescription " +
         "FROM tblBrands " +
         "INNER JOIN tblSupplierData ON tblBrands.fldId = tblSupplierData.fldBrandSystem " +
         "WHERE (tblSupplierData.fldSupplierId = @supplierId) " +
         "GROUP BY tblBrands.fldId, tblBrands.fldDescription " +
         "ORDER BY tblBrands.fldDescription", sqlConn);

     getBrandsViaSupplier.Parameters.AddWithValue("@supplier", supplier);
     var brands = new List<Brand>();
     sqlConn.Open();

     var reader = getBrandsViaSupplier.ExecuteReader();
     if (reader.HasRows)
     {
         while (reader.Read())
         {
             var brand = new Brand();
             brand.BrandId = reader[0].ToString();
             brand.BrandDescription = reader[1].ToString();
             brands.Add(brand);
         }
     }
     reader.Close();
     sqlConn.Close();

     return brands;
 }


Thanks for any help
Posted
Comments
Mitchell J. 24-Jan-14 20:25pm    
Do you have the source of the ExecuteReader() function?
Stu Baby 24-Jan-14 20:42pm    
Hi Craig, you've confused me. Isn't that a part of SqlCommand?
Eric James Zimmerman 24-Jan-14 20:32pm    
What do you mean by it exits?
I'm assuming that means it is throwing an exception... I would put a try..catch around that call and set a breakpoint in the catch to see what the problem is.
Stu Baby 24-Jan-14 20:40pm    
By exit, I mean leave the code altogether, no exceptions and everything looks fine. If I'm hitting F11, stepping through the code, line by line, it hits the mentioned line and then goes to the form.show that calls this. (This is called from a constructor)
Karthik_Mahalingam 24-Jan-14 20:36pm    
what problem you are facing ?

1 solution

Aggggggh, thanks to all for you time here. Big rookie error

getBrandsViaSupplier.Parameters.AddWithValue("@supplier", supplier);

should be

getBrandsViaSupplier.Parameters.AddWithValue("@supplierId", supplier);

Never had visual studio / c# behave that way before though at such an error. Once again, thanks so much for your input.
 
Share this answer
 
Comments
Karthik_Mahalingam 24-Jan-14 21:30pm    
good,
mark it as answer..
BillWoodruff 24-Jan-14 22:45pm    
Does this really belong here as a "solution" ? In this case the error is a simple syntax error; there's no content here which adds value to CP in the future.

Or, should the OP simply update his post to indicate there problem is resolved ? I'm just asking, and I'm not down-voting this.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900