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
ahmed sa
NA
289
128.8k
error Object cannot be cast from DBNull to other types.
Apr 20 2015 3:50 AM
Hi guys i have problem
Firstly this is all my code
Function MaxTotalQuantity
public int MaxTotalQuantity(string ConnectionString)
{
SqlConnection con = new SqlConnection(ConnectionString);
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandType = CommandType.Text;
cmd.CommandText = "select max(TotalQuantity) from dbo.EndWork";
con.Open();
int commit = Convert.ToInt32(cmd.ExecuteScalar());
con.Close();
return commit;
}
Calling function
Sales.SalesClass SalesClass4 = new Sales.SalesClass();
int TotalQuantity = SalesClass4.MaxTotalQuantity("Data Source=192.168.1.3;Initial Catalog=yamo;User ID=admin;Password=2233;Connection Lifetime=3;Max Pool Size=3;Connection Timeout=30");
label10.Text = TotalQuantity.ToString();
End work table
ID intUnchecked
QunatityEndintChecked
Positionnvarchar(50)Checked
IssentintChecked
TotalQuantityintChecked
Unchecked
But error show to me when run code it give me
error Object cannot be cast from DBNull to other types.
Some times value found in TotalQuantity is null
What i need is to convert null to 0 when is null is found show as 0 and exception not show
How to solve this problem
Reply
Answers (
6
)
C# .NET – how to Integrate QuickBooks windows application?
email sending in c#