CMD = New SqlCommand("Select * From Jenis where KodeJenis='" & CBjenis.Text & "'", CONN)
RD = CMD.ExecuteReader()
CONN.Open()
RD.Read()
If RD.HasRows = True Then
TextBox2.Text = RD.Item(1)
Else
MsgBox("Kode jenis ini tidak terdaftar")
End If
有什么问题?
答案 0 :(得分:0)
尝试使用Using End Using
语法来避免未关闭的连接。
Dim rd As SqlDataReader
Using CMD = New SqlCommand
CMD.CommandText = "Select * From Jenis where KodeJenis='" & CBjenis.Text & "'"
CMD.CommandType = CommandType.Text
CMD.Connection = CONN
CMD.Connection.Open()
rd = CMD.ExecuteReader
If rd.Read() Then
TextBox2.Text = rd.Item(1)
Else
MsgBox("Kode jenis ini tidak terdaftar")
End If
End Using
End Sub