C# 代码明明有获取到数据,为什么还会出现错误“未将对象引用设置到实例”

public TheCustomCheckDetailObj GetTheCustomCheckDetail(int TheCustomCheck)
{
using (SqlConnection con = new SqlConnection(_connectionString))
{
con.Open();
SqlCommand cmd = new SqlCommand("OGetTheCustomCheckDetail", con);
cmd.CommandType = CommandType.StoredProcedure;

            cmd.Parameters.Add("@TheCustomCheck", SqlDbType.Int);
            cmd.Parameters["@TheCustomCheck"].Value = TheCustomCheck;

            SqlDataReader reader = cmd.ExecuteReader();

            while (reader.Read())
            {
                obj.CurrentCustomDetailObj.CompanyName = Convert.ToString(reader["CompanyName"]);
                obj.CurrentCustomDetailObj.CompanyPart = Convert.ToString(reader["CompanyPart"]);
                obj.CurrentCustomDetailObj.CompanyWebsite = Convert.ToString(reader["CompanyWebsite"]);
                obj.CurrentCustomDetailObj.CustomName = Convert.ToString(reader["CustomName"]);
                obj.CurrentCustomDetailObj.CustomCellphone = Convert.ToString(reader["CustomCellphone"]);
                obj.CurrentCustomDetailObj.CustomPhone = Convert.ToString(reader["CustomPhone"]);
                obj.CurrentCustomDetailObj.CustomFenji = Convert.ToString(reader["CustomFenji"]);
                obj.CurrentCustomDetailObj.QQorMSN = Convert.ToString(reader["QQorMSN"]);
                obj.CurrentCustomDetailObj.Email = Convert.ToString(reader["Email"]);
                obj.CurrentCustomDetailObj.BusinessID = Convert.ToInt32(reader["BusinessID"]);
                obj.CurrentCustomDetailObj.ProvinceID = Convert.ToInt32(reader["ProvinceID"]);
                obj.CurrentCustomDetailObj.CountryID = Convert.ToInt32(reader["CountryID"]);
                obj.CurrentCustomDetailObj.CityID = Convert.ToInt32(reader["CityID"]);
                obj.CurrentCustomDetailObj.Address = Convert.ToString(reader["Address"]);
                obj.CurrentCustomDetailObj.PS = Convert.ToString(reader["PS"]);


                obj.InCheckCustomDetailObj.CompanyName = Convert.ToString(reader["OldCompanyName"]);
                obj.InCheckCustomDetailObj.CompanyPart = Convert.ToString(reader["OldCompanyPart"]);
                obj.InCheckCustomDetailObj.CompanyWebsite = Convert.ToString(reader["OldCompanyWebsite"]);
                obj.InCheckCustomDetailObj.CustomName = Convert.ToString(reader["OldCustomName"]);
                obj.InCheckCustomDetailObj.CustomCellphone = Convert.ToString(reader["OldCustomCellphone"]);
                obj.InCheckCustomDetailObj.CustomPhone = Convert.ToString(reader["OldCustomPhone"]);
                obj.InCheckCustomDetailObj.CustomFenji = Convert.ToString(reader["OldCustomFenji"]);
                obj.InCheckCustomDetailObj.QQorMSN = Convert.ToString(reader["OldQQorMSN"]);
                obj.InCheckCustomDetailObj.Email = Convert.ToString(reader["OldEmail"]);
                obj.InCheckCustomDetailObj.BusinessID = Convert.ToInt32(reader["OldBusinessID"]);
                obj.InCheckCustomDetailObj.ProvinceID = Convert.ToInt32(reader["OldProvinceID"]);
                obj.InCheckCustomDetailObj.CountryID = Convert.ToInt32(reader["OldCountryID"]);
                obj.InCheckCustomDetailObj.CityID = Convert.ToInt32(reader["OldCityID"]);
                obj.InCheckCustomDetailObj.Address = Convert.ToString(reader["OldAddress"]);
                obj.InCheckCustomDetailObj.PS = Convert.ToString(reader["OldPS"]);


            }


            reader.Close();
            con.Close();

            return obj;

        }
    }
c#

2个回答

具体是哪一行?看看是不是哪个字段你搞错了,实际不存在。

特别是细微的拼写错误。知道出错的行,再仔细检查下。

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问