我需要选择最小自动增量编号,然后在选择学生信息时选择ID编号作为参考。这就是我所拥有的:
strSQL = "SELECT min(number) from main_queue "
cmd = New MySqlCommand(strSQL, CONNECTION)
dr = cmd.ExecuteReader
If dr.HasRows Then
dr.Read()
Dim min As Integer
min = dr("min(number)")
strSQL = "SELECT idno_ from main_queue where number='" + min + "'"
cmd = New MySqlCommand(strSQL, CONNECTION)
If dr.HasRows Then
dr.Read()
Dim idnum As Integer
idnum = dr("idno_")
strSQL = "SELECT * from student_records where number='" + idnum + "'"
cmd = New MySqlCommand(strSQL, CONNECTION)
If dr.HasRows Then
dr.Read()
mon_name.Text = dr("name_")
mon_IDno.Text = dr("IDno")
End If
End If
End If
我收到“从字符串转换”“到'Double'类型无效。”行中的错误,我使用最小自动增量编号作为参考选择id号。
答案 0 :(得分:1)
也许我对您的数据库架构没有正确理解,但似乎您可以在一个查询中全部编写
Dim strSQL = "SELECT * FROM student_records " & _
"where idNO = " & _
"(SELECT idno_ from main_queue where number= " & _
"(SELECT min(number) from main_queue))"
cmd = New MySqlCommand(strSQL, CONNECTION)
If dr.Read() Then
mon_name.Text = dr("name_")
mon_IDno.Text = dr("IDno")
End If
答案 1 :(得分:0)
设法让它发挥作用!这是我的代码
SELECT * from student_records where IDno in (select idno_ from main_queue where number in (SELECT min(number) as min_number from main_queue))