0

我有一个使用 SqlDataReader 从数据库表中读取数据的方法。我将 SqlDataReader 检索到的数据分配到一个列表中并返回它。当我想将列表数据从方法分配到代码隐藏文件列表中时,我遇到以下错误:在此处输入图像描述

这是我的代码

public List<string> displayCustoemrhShipOrder()
    {
        List<string> drList = new List<string>();
        int i = 0;

        string sConnectionString = ConfigurationManager.ConnectionStrings["LGDB"].ToString();
        SqlConnection SqlCOn = new SqlConnection(sConnectionString);
        SqlCommand SqlCmd = new SqlCommand();
        SqlCmd.Connection = SqlCOn;
        SqlCmd.CommandText = "displayCustomerShipOrder";
        SqlCmd.CommandType = CommandType.StoredProcedure;
        SqlCOn.Open();
        SqlCmd.Parameters.AddWithValue("ShipOrderID",shipOrderID);
        SqlDataReader reader = SqlCmd.ExecuteReader();
        while (reader.Read())
        {
            drList.Insert(i, reader.GetValue(i).ToString());
            i++;               
        }
        //reader.Close();
        //sqlCon.Close();
        reader.Dispose();
        SqlCOn.Dispose();
        return (drList);
    }

代码后面的代码:

protected void Page_Load(object sender, EventArgs e)
    {

       // string shipOrderID = Session["shipOrderID"].ToString();
       //  int ID = Convert.ToInt32(shipOrderID);
        int ID = 700;
         Classes.CustomerShipOrder cuShipOrder = new Classes.CustomerShipOrder(ID);
         List<string> ordrList = new List<string>(16);
          ordrList= cuShipOrder.displayCustoemrhShipOrder();
          cuid.Text = ordrList[0];            
          Label2.Text = ordrList[1];
          Label3.Text = ordrList[2];
          Label4.Text = ordrList[3];
          Label5.Text = ordrList[4];
          Label6.Text = ordrList[5];
          Label7.Text = ordrList[6];
          Label8.Text = ordrList[7];
          Label9.Text = ordrList[8];
          Label10.Text = ordrList[9];
          Label11.Text = ordrList[10];

使用的存储过程:

@ShipOrderID int

as
begin 

select * from customerShipOrder where shipOrderID = @ShipOrderID;
end
4

0 回答 0