G
Guest
When executing the following code
ArrayList list = new ArrayList();
try
{
//Make sure connection is open
if (!connection.State.ToString().Equals("Open"))
connection.Open();
DataSet list = new DataSet();
SqlDataAdapter da = new SqlDataAdapter("select " + m_TableSerieColName + "
from " + m_TableSerie, connection);
DataSet ds = new DataSet();
da.Fill(ds);
foreach (DataRow dr in ds.Tables[m_TableSerie].Rows) //<-----
list.Add((string) dr[m_TableSerieColName]);
}
catch (SqlException exc)
{
MessageBox.Show(exc.Message);
return;
}
I get the following exception:
---
An unhandled exception of type 'System.NullReferenceException' occurred in
SportsResult.exe
Additional information: Object reference not set to an instance of an object.
---
on the line
foreach (DataRow dr in ds.Tables[m_TableSerie].Rows) //<-----
Rows has a length of 0, so what I expect is the foreach loop to execute 0
times, but instead I then get the exception. Why?
ArrayList list = new ArrayList();
try
{
//Make sure connection is open
if (!connection.State.ToString().Equals("Open"))
connection.Open();
DataSet list = new DataSet();
SqlDataAdapter da = new SqlDataAdapter("select " + m_TableSerieColName + "
from " + m_TableSerie, connection);
DataSet ds = new DataSet();
da.Fill(ds);
foreach (DataRow dr in ds.Tables[m_TableSerie].Rows) //<-----
list.Add((string) dr[m_TableSerieColName]);
}
catch (SqlException exc)
{
MessageBox.Show(exc.Message);
return;
}
I get the following exception:
---
An unhandled exception of type 'System.NullReferenceException' occurred in
SportsResult.exe
Additional information: Object reference not set to an instance of an object.
---
on the line
foreach (DataRow dr in ds.Tables[m_TableSerie].Rows) //<-----
Rows has a length of 0, so what I expect is the foreach loop to execute 0
times, but instead I then get the exception. Why?