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
Praveen Maurya
NA
146
27k
Object cannot be cast from DBNull to other types
Apr 26 2018 7:33 AM
i want to calculate sum table values but at startup my application the table is having null value and it show error like .....Object cannot be cast from DBNull to other types
Please suggest how i can solve this.
SqlDataAdapter sda21 =
new
SqlDataAdapter(
"select * from sale_total"
, con);
DataTable dt21 =
new
DataTable();
sda21.Fill(dt21);
int
sum = Convert.ToInt32(dt21.Compute(
"SUM(gtot)"
,
string
.Empty));
SqlDataAdapter sda22 =
new
SqlDataAdapter(
"select * from exp_total"
, con);
DataTable dt22 =
new
DataTable();
sda22.Fill(dt22);
int
sum1 = Convert.ToInt32(dt22.Compute(
"SUM(gtot)"
,
string
.Empty));
metroTile13.Text =
"\u20B9 "
+ sum1.ToString() +
".00"
;
if
(sum1 < sum)
{
int
sum2 = sum - sum1;
label2.Text =
"\u20B9 "
+ sum2.ToString() +
".00"
;
metroTile6.Text =
"\u20B9 "
+ sum2.ToString() +
".00"
;
}
if
(sum1 > sum)
{
int
sum2 = sum1 - sum;
label2.Text =
"\u20B9 "
+ sum2.ToString() +
".00"
;
metroTile6.Text =
"\u20B9 "
+ sum2.ToString() +
".00"
;
}
Reply
Answers (
6
)
Parameterized query for like clause to avoid sql injection
Problem in drop down list binding.