your code is correct just make some change
remove
r1.Read();
if(r1[0]==0)
{
increment_id = 1;
}
else
{
increment_id = int.parse(dr[0].toString()) + 1;
}
and add
if r1.hasrows();
while (r1.read())
{
if (r1[0].tostring()=="0")
{
increment_id=1
}
else
{
int.parse(r1[1].toString()) + 1;
}
}
Now, there will not be error, but still any error occurs then give deals about error....