I have this code on my page
private object getJobID()
{
try
{
conn.Open();
String latestJobID = @"SELECT MAX(jobId) + 1 FROM joborder";
MySqlCommand cmd = new MySqlCommand(latestJobID, conn);
MySqlDataReader DR = cmd.ExecuteReader();
while (DR.Read())
{
return DR[0].ToString();
}
}
catch (MySqlException ex)
{
System.Diagnostics.Debug.WriteLine("ERROR: " + ex.ToString());
}
finally
{
conn.Close();
}
return "";
}
the @"SELECT MAX(jobId) + 1 FROM joborder"
do not add + 1 if my table is empty, how can i Add + 1 to my jobId if my table is null, thanks
您可以在查询中测试 null
select COALESCE(MAX(jobId), 0) + 1 FROM joborder
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.