在查询按钮下:
strsql = "SELECT patID ,"
strsql &= "patnam, "
strsql &= "patnamkan,"
strsql &= "patbirdat,"
strsql &= "patsex, "
strsql &= "numpatrelstu "
strsql &= "From PatientLevel "
If txtPatName.Text <> "" Then
strsql &= "and patnam like '" & txtPatName.Text & "' "
ElseIf txtPatID.Text <> "" Then
strsql &= "and patID like '" & txtPatID.Text & "%' "
ElseIf cboPatSex.Text <> "" Then
strsql &= "and patsex = '" & cboPatSex.Text & "' "
End If
Try
dt.Clear()
cn.Open()
da = New SqlDataAdapter(strsql, cn)
da.Fill(dt)
grdPatList.DataSource = dt
btnModify.Enabled = True
btnDel.Enabled = True
If dt.Rows.Count = 0 Then
MsgBox("该查询结果不存在。")
End If
da.Dispose()
Catch ex As Exception
MsgBox(ex.Message)
Finally
If cn.State = ConnectionState.Open Then
cn.Close()
End If
End Try