Hullo Friends,
I do need your Help. Please help me.
I am using C#NET2008 for Window application to export data to Microsoft Excel 2003 Spreadsheet.
I am very surprised that the (DataReader) DR.HasRow display TRUE means that it has record
but the system display error message
Invalid attempt to read when no data is present.
Here are the over coding:
private void FRetrieveCustomerDetails()
{ //retrieve Customer details for Excel Banner Header --
string strsql = string.Empty;
strsql += " Select CompanyName, Address, City, Country, PostalCode ";
strsql += " From TestCustomers ";
strsql += " Where (CustomerID = N'" + strCustID + "')";
sqlconn.Open();
sqlcmd = new SqlCommand(strsql, sqlconn);
DR = sqlcmd.ExecuteReader(CommandBehavior.CloseConnection);
{
strCustName = Convert.ToString(DR.GetValue(1)); <-- error
strCustAdd = Convert.ToString(DR.GetValue(2)); <-- error
strCustCity = Convert.ToString(DR.GetValue(3)); <-- error
strCustCity += " PostalCode : " + Convert.ToString(DR.GetValue(4)); <-- error
strCustCountry = Convert.ToString(DR.GetValue(5)); <-- error
}
sqlconn.Close();
sqlcmd.Dispose();
DR.Dispose();
}
Thank you for helping me.
Cheers,
Lennie Kuah
Lennie KuahPosted Sep 25, 2011, 1:29 AM
The Error section of the programmer is working now after I added this login to it.
if (DR.HasRow == true )
{
WHILE (DR.READ())
{
}
}
Your suggestion inspired me to identify the mistake I made.
You are wonderful and awesome.....Ya...Hoooo
Prabhu RajaPosted Sep 25, 2011, 12:50 AM
Lennie KuahPosted Sep 24, 2011, 5:56 PM
Thank you for your suggestin.
I will try it out and get back to you with the result.
As appreciation of your help I will post the over all coding to share it with other newbies who may have similar problems.
Thank you very much. You are wonderful, Awesome and very helpful.
I am so glad to meet you here a wonderful FORUM.
Cheers,
Lennie
Prabhu RajaPosted Sep 24, 2011, 5:52 AM