TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Jes Sie
742
1.2k
282.1k
Initializing null value
May 12 2017 2:28 AM
Once again I need your help. I have a webpage in my web application. On page load, it looks up the credit limit and the accounts receivable of an agent. Below is my code and works fine if the accounts receivable has value:
private
void
GetCreditLimit()
{
using
(SqlConnection con = DBConnection.GetDbCon())
{
SqlCommand cmd =
new
SqlCommand(
"spGetAgentCreditLimitAndARBalance"
, con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue(
"@AgentID"
, lblAgentCode.Text);
using
(SqlDataAdapter da =
new
SqlDataAdapter(cmd))
{
DataSet ds =
new
DataSet();
da.Fill(ds);
try
{
lblCreditLimit.Text = ds.Tables[0].Rows[0][
"CreditLimit"
].ToString();
lblARBalance.Text = ds.Tables[0].Rows[0][
"ARBalance"
].ToString();
}
catch
(Exception ex)
{
throw
ex;
}
}
}
}
But when the accounts receivable has no value, it gives me this error:
Server Error in '/' Application.
There is no row at position 0.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.IndexOutOfRangeException: There is no row at position 0.
When I will deploy this program, all the accounts receivable will be set to null or zero. This means I will be facing a problem when a certain agent first time uses the program. Can someone advice or show me on how to deal with this error?
Thanks for your help.
Reply
Answers (
6
)
BootStrap TreeView issue.
How to Fetch Current Time from Internet?