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
David Smith
NA
2k
0
Datatable Index and ColumnName Validation
Dec 15 2014 4:27 AM
Can someone assist me with the logic to validate the rowindex is in range and also valid the columnName? How would I do that with the logic below.
The task is to create my own custom exception derived from ApplicationException. However for this thread I am looking for the robust logic to valid index and column name.
public static int GetIntValue(this DataTable datatable, int rowindex, string columnName)
{
try
{
//if index is out bounds throw out of bounds;
// return what is asking for
if (datatable != null)
{
if (rowindex > -1 && rowindex < datatable.Rows.Count - 1)
{
return Convert.ToInt32(datatable.Rows[rowindex][columnName]);
}
else
{
//return custom exception
}
}
else
{
//return custom exception
}
}
catch (Exception ex)
{
throw new Exception("GetIntValue: \n" + ex.Message);
}
}
Reply
Answers (
3
)
Regex 1512
he has worked how many hours ? c#, datetme, timespan