我想要获得最大数量的值。但它没有用。
drqry = "SELECT max(num) FROM tbCVinfo WHERE cvabbrv LIKE '%" & abbrv & "%' and `year` LIKE '%" & year & "%'"
'drqry = "SELECT max(cvno) FROM tbCVinfo WHERE cvno LIKE '%" & cvstr & "%'"
cmd2.CommandText = drqry
cmd2.Connection = con
dr = cmd2.ExecuteReader
Dim result As String = ""
If dr.Read() Then
dr.Close()
cv = Convert.ToInt32(cmd2.ExecuteScalar()) ''''i am having an error in this part. it says "Object cannot be cast from DBNull to other types." upon checking all datas in the database, I don't have null values
cv = cv + 1
If cv >= 0 And cv <= 9 Then
result = "000" & cv
答案 0 :(得分:0)
如果您尝试获取最大数量,则第一个查询应改为:
drqry = "SELECT max(num) FROM tbCVinfo WHERE cvabbrv LIKE '%" & abbrv & "%' and `year` LIKE '%" & year & "%'"
答案 1 :(得分:0)
这是我的代码。是的,它现在正在运行。非常感谢您的帮助。
drqry = "SELECT max(num) FROM tbCVinfo WHERE cvno LIKE '%" & cvstr & "%'"
cmd2.CommandText = drqry
cmd2.Connection = con
Dim result As String = ""
cv = Convert.ToInt32(cmd2.ExecuteScalar())