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
Ashfaque Baig
NA
66
2.9k
Object cannot be cast from DBNull to other types.
Apr 13 2020 10:22 AM
I am getting issue while tab reach to next new row after loading data from database.
Can anyone please correct the code
private
void
dataGridSALEITEM_CellValueChanged(
object
sender, DataGridViewCellEventArgs e) {
decimal
TOTALAMOUNT = 0;
decimal
TOTALCGST = 0;
decimal
TOTALSGST = 0;
decimal
NETTOTAL = 0;
foreach
(DataGridViewRow row
in
dataGridSALEITEM.Rows) {
row.Cells[dataGridSALEITEM.Columns[7].Index].Value = (Convert.ToInt32(row.Cells[dataGridSALEITEM.Columns[3].Index].Value) * Convert.ToInt32(row.Cells[dataGridSALEITEM.Columns[4].Index].Value));
row.Cells[dataGridSALEITEM.Columns[8].Index].Value = (Convert.ToInt32(row.Cells[dataGridSALEITEM.Columns[7].Index].Value) / 200 * Convert.ToInt32(row.Cells[dataGridSALEITEM.Columns[5].Index].Value));
row.Cells[dataGridSALEITEM.Columns[9].Index].Value = (Convert.ToInt32(row.Cells[dataGridSALEITEM.Columns[7].Index].Value) / 200 * Convert.ToInt32(row.Cells[dataGridSALEITEM.Columns[5].Index].Value));
row.Cells[dataGridSALEITEM.Columns[10].Index].Value = (Convert.ToInt32(row.Cells[dataGridSALEITEM.Columns[7].Index].Value) + Convert.ToInt32(row.Cells[dataGridSALEITEM.Columns[8].Index].Value) + Convert.ToInt32(row.Cells[dataGridSALEITEM.Columns[9].Index].Value));
TOTALAMOUNT += Convert.ToDecimal(row.Cells[dataGridSALEITEM.Columns[7].Index].Value);
TOTALCGST += Convert.ToDecimal(row.Cells[dataGridSALEITEM.Columns[8].Index].Value);
TOTALSGST += Convert.ToDecimal(row.Cells[dataGridSALEITEM.Columns[9].Index].Value);
NETTOTAL += Convert.ToDecimal(row.Cells[dataGridSALEITEM.Columns[10].Index].Value);
}
txtSUBTOTAL.Text = TOTALAMOUNT.ToString();
txtCGST.Text = TOTALCGST.ToString();
txtSGST.Text = TOTALSGST.ToString();
txtGTOTAL.Text = NETTOTAL.ToString();
}
Reply
Answers (
3
)
How to do If Statement to detect multiple words in a string?
how to find the top 50 words used in a text file