Re: NullReferenceException when connection to ASP.NET website
You are using ODBCDataReader incorrectly (http://msdn.microsoft.com/en-us/library/system.data.odbc.odbcdatareader_methods.aspx). Columns are referenced via ordinal not name.
while (dr.Read())
{
int intID = dr.GetInt32(0);
string strName = dr.GetString(1);
}
Alternatively you can load a DataTable via OdbcDataAdapter. You can reference columns by name from the DataTable.
command.CommandText = _sql;
OdbcDataAdapter _adapter = new OdbcDataAdapter(command);
System.Data.DataTable _dataTable = new System.Data.DataTable();
_adapter.Fill(_dataTable);
if (_dataTable.Rows.Count > 0)
{
foreach (System.Data.DataRow _dr in _dataTable)
{
string id = _dr["ID"].ToString();
string name = _dr["Name"].ToString();
}
}
DataRow :
http://msdn.microsoft.com/en-us/library/system.data.datarow.aspx
Subject
Written By
Posted
Re: NullReferenceException when connection to ASP.NET website
January 06, 2010 08:25AM
Sorry, you can't reply to this topic. It has been closed.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion
of Oracle or any other party.