Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DataRow array NullReferenceException help!!

Status
Not open for further replies.

laic

IS-IT--Management
Jul 24, 2003
17
US
I have a question about accessing a datarow array which result to be "Object reference not set to an instance of an object."

Below is my code in brief:
//****************************************************
private DataTable DT;
private DataRow[] DR;
private Repeater rep;
protected System.Web.UI.WebControls.Label Label1;

private DataRow[] SortRow(string year, string month, string day)
{
//I have already made the SQL connection and successfully
//show my data in a datagrid.
return DT.Select("Year='" + year + "' AND Month='" + month + "' AND Day = '" + day "'";
}

private void RepeaterBind()
{
DR = SortRow("2005", "04", "26");
rep.DataSource = DR;
rep.DataBind();
}

private void showRow()
{
for(int i = 0; i < DR.length; i++)
Label1.text = DR["Purpose"]; //NullReferenceException
//just to check if the data from SortRow are still there.
}
//****************************************************

I understand that when I declare DataRow = DR, I did not initialize it and give an array size.
However, even if I did give it a size, and initilaize, it will not have an error, but the data are not in the DR.
It seems that data in DR only live in that RepeaterBind() block. Once out of that block, the reference is gone.

Is there anyway to fix this thing?? or ??
I am not sure if this has anything to do with deep copy array.
Please help me out here, I've stuck on this issue for
4 days already.

Laic
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top