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();
}
}
}
I try to populate my tab control pages using data from SQL Server, which I already got, but I want to set the name property too to the same value I extracted from my database. It throws an error
System.NullReferenceException: 'Object reference not set to an instance of an object.'