“System.IndexOutOfRangeException”类型的未经处理的异常在 System.Data.dll 中发生
目的是实现模糊查询相关内容,但执行到“****”位置时出现标题所述异常,大家帮忙看看是怎么回事Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim cns As String = "Data Source=TSTAR;Initial Catalog=university;Integrated Security=True"
Dim sql As String = "select student.snum,sname,cname,score from student join sc on student.snum=sc.snum join sections on sc.secnum=sections.secnum join course on where student.snum like '%" & TextBox1.Text & "%' or sname like'%" & TextBox2.Text & "%'"
Dim con As New SqlConnection(cns)
Dim sqlc As New SqlCommand(sql, con)
con.Open()
Dim rdr As SqlDataReader = sqlc.ExecuteReader()
While rdr.Read()
Dim li As New ListViewItem()
li.SubItems.Clear()
li.SubItems(0).Text = rdr("student.snum").ToString()****
li.SubItems.Add(rdr("sname").ToString())
li.SubItems.Add(rdr("cname").ToString())
li.SubItems.Add(rdr("score").ToString())
ListView1.Items.Add(li)
End While
rdr.Close()
con.Close()
End Sub