|
-
May 14th, 2009, 02:01 PM
#1
Help with While (reader.read) loop
I am using while (reader.Read() ) to read the rows from excel spreadsheet and want to exit when the last row has been read. I am using the code below. Some how it is always selecting one extra row.
Any help would be appreciated.
while (reader.Read() )
{
string AgentID = Convert.ToString(reader["Sales ID"]);
string Notes = Convert.ToString(reader["Notes"]);
string AdjAmount = Convert.ToString(reader["Adjustment"]);
string AdjustmentType = "";
if ((AdjAmount == null) || (AgentID == null) || (Notes == null))
{
r = 3; //return value to the calling method
}
else
{
if (Convert.ToString(reader[3]) == "")
{
r = imp.Insert_tblSummaryAdjustment_New("", AdjAmount, AgentID, Notes, xlsheetname, year, month);
import.Update_tblSummaryAdjustment(AgentID);
}
else
{
AdjustmentType = Convert.ToString(reader["AdjustmentType"]);
//AdjustmentType = Convert.ToString(reader[1]);
r = imp.Insert_tblSummaryAdjustment(AdjustmentType, AdjAmount, AgentID, Notes, xlsheetname, year, month);
}
}
}
reader.Close();
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|