我正在尝试获取最大值

2guxujil  于 2021-06-24  发布在  Mysql
关注(0)|答案(2)|浏览(263)

我想得到最大值。但它不起作用。

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
r8xiu3jd

r8xiu3jd1#

这是我的密码。是的,它现在正在运行。非常感谢你的帮助。

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())
5fjcxozz

5fjcxozz2#

如果您试图获取最大值,则第一个查询应该是:

drqry = "SELECT max(num) FROM tbCVinfo WHERE cvabbrv LIKE '%" & abbrv & "%' and `year` LIKE '%" & year & "%'"

相关问题