int sel = int.Parse(0+dataGridView2.CurrentRow.Cells["invoice_ID"].Value.ToString());

string sql = "DELETE FROM invoices WHERE invoice_id="+ sel +"";
DBConnection myCon = new DBConnection(); 

myCon.EditValues(sql); 

//mycon.EditeValues(sql) has all the sqldata reader,executenonQuery cmd

the error's arrow points out to the first line which is "int sel............".

Your 0 is an integer not a string, which you are trying to concatenate to and send to a method which accepts String. You just need to put quotes around the 0 :)

As Ketsuekiame said if you're invoice is alph-numeric (letters and numbers) you can't parse it into an int.

Try taking the int.parse and .ToString() off the first line and adding (int)before the name dataGridView2 (that will also only work if the cell doesn't contain letters but it means you're not converting it to a string before trying to store it in an int).

I tried

with "0", 0, and without 0 or "0"

Perhaps try:

if(!int.TryParse("0"+dataGridView2.CurrentRow.Cells["invoice_ID"].Value.ToString(),out int sel))
    MessageBox("0"+dataGridView2.CurrentRow.Cells["invoice_ID"].Value.ToString());

This way you can see exactly why the string is not parsing right. If there is anything in the string that isn't a digit, a comma, or a period then it will fail.

I just convereted int to string. that is it. >string< sel fixed it. I wonder why :O. Thanks!!

probably cause sql is declared as a string.

LOL When in doubt, convert to a string.

To all my more experience member, think about how many times this has fixed an issue (at least this seems true so many times for me)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.