You are only populating the DataGridView if exactly one row is returned from the database...
if (dt.Rows.Count == 1)< lang=
so check that you don't have more then one row being returned - debugging will help you determine this.
You also only have 6 columns on your table but you are looking at the 7th with
if (TAB_Credit.CurrentCell.ColumnIndex == 6)
Remember that the column collection is zero-based - 1st column is 0, 2nd column is 1 etc.
To find out what is going on you will have to debug - put a breakpoint on the line
if (TAB_Credit.Columns[e.ColumnIndex].Name == "Reference")
You haven't said what is wrong with your calculation of the total, but I can tell you that you are ignoring the first row with the for loop
for (int i = 0; i < TAB_Credit.Rows.Count; ++i)
You are pre-incrementing i rather than post-increment. I believe that line should be
for (int i = 0; i < TAB_Credit.Rows.Count; i++)
A subtle, but important difference. Again, you can confirm all of this by debugging. I believe I have already given you a link to an article on how to do that.