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
Tejas Kullarwar
NA
4
22.3k
Not able to import a specific excel cell to a textbox C#
Apr 24 2013 7:07 AM
Hi I am trying to import value of a specific excel cell to a textbox on the form. The value will appear as soon as the form loads. Now this cell can be null and I am taking care of the null value but it is throwing an exception and going into catch everytime a null value is passed. Here is the snippet of my code:
try
{
var v;
if
( oSheet.Cells[3, 4].Value2 != null)
{v =
Sheet.Cells[3, 4].Value2;
var s =
Convert
.ToString(v);
textBox1 =
string.
Format(
"{0:N2}"
, s);
}
else
{ v = 0;
var s =
Convert
.ToString(v);
textBox1 =
string.
Format(
"{0:N2}"
, v);
}
}
catch(
Exception
)
{
string
errorMessage =
"Data cannot be retrieved from the strats file "
;
MessageBox
.Show(errorMessage);
}
The catch is showing this exception "
object reference not set to an instance of an object"
Reply
Answers (
0
)
BEST BOOK FOR C SHARP
Conversion from "I" to "K"