以下代码出现问题。 (是的,我是初学者) [英] Problem with the following code. (Yes, I'm a beginner)

查看:113
本文介绍了以下代码出现问题。 (是的,我是初学者)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,以下代码退出该行:



var reader = getBrandsViaSupplier.ExecuteReader();



查询工作正常并返回我的预期,代码格式与大约50种其他方法完全一致。



为什么会发生这种情况,我该如何跟踪这种行为?



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?

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

推荐答案

Aggggggh感谢大家在这里的所有时间。大新秀错误



getBrandsViaSupplier.Parameters.AddWithValue(@ supplier,供应商);



应该是


getBrandsViaSupplier.Parameters.AddWithValue(@ supplierId,供应商);



从未有过视觉studio / c#在出现这种错误之前表现得那么好。再一次,非常感谢您的投入。
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.


这篇关于以下代码出现问题。 (是的,我是初学者)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆