任何人都可以帮助我我无法在选项卡控件 C# 中初始化我的选项卡页面的名称属性这是我的代码

问题描述 投票:0回答:0
 using (Connection = new SqlConnection(CS))
                {
                    SqlDataAdapter adapter = new SqlDataAdapter("SELECT category_name FROM book_category", Connection);
                    Connection.Open();
                    DataTable dt_category = new DataTable();
                    adapter.Fill(dt_category);
                    if (dt_category.Rows.Count > 0)
                    {
                        categories = new string[dt_category.Rows.Count];

                        for (int count = 0; count < dt_category.Rows.Count; count++)
                        {
                            DataRow category_row = dt_category.Rows[count];
                            //Populate Tab Page for our tab control
                            tc.TabPages.Add(category_row[0].ToString().ToUpper());
                            tc.TabPages[category_row[0].ToString()].Name = category_row[0].ToString();
                            //Store Categories data to global Array variable categories for further use
                            categories[count] = category_row[0].ToString().ToUpper();
                        }

                    }
                }

我尝试使用来自 MSSQL 服务器的数据来填充我的选项卡控制页面,我已经获得了这些数据,但我也想将名称属性设置为我从数据库中提取的相同值。它抛出 System.NullReferenceException:“对象引用未设置为对象的实例。”

c# sql-server nullreferenceexception tabcontrol
最新问题
© www.soinside.com 2019 - 2025. All rights reserved.