I have a function here that gets the last value of an order_id
and increments it by 1 if it's not already 1. Problem is, the initial value is null and I couldn't get it to add by 1.
Code:
private void getOrderId()
{
var orders_dt = conn.Select("orders", "MAX(order_id)").GetQueryData();
if (orders_dt == null || orders_dt.Rows.Count == 0 || orders_dt.Rows[0][0] == null)
{
//Should not preemptively insert into the database
order_no.Text = "1";
}
else
{
int order_id = orders_dt.Rows[0][0] + 1; //ERROR HERE
order_no.Text = order_id.ToString();
}
}
An error occurs on int order_id = orders_dt.Rows[0][0] + 1;
Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: 'Operator '+' cannot be applied to operands of type 'System.DBNull' and 'int''
Any ideas?
Edit: I've already confirmed the query in MySql, it returns null.