0

我尝试使用 cmbo 框在 sql 数据库中搜索数据记录。在此“附近的语法不正确”之后显示错误“找不到多部分标识符“System.Data.DataRowView”。我的代码如下。

 Private Sub BTNEDIT_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BTNEDIT.Click
    refreshComboBox()
    CMBID.SelectedText = "Select"
 End Sub

 Private Sub refreshComboBox()
    getConnect()
    Try
        Conn.Open()
        Dim strSQL As String = "SELECT * FROM EMPLOYEE ORDER BY EMP_ID ASC"
        Dim da As New SqlDataAdapter(strSQL, Conn)
        Dim ds As New DataSet
        da.Fill(ds, "EMPLOYEE")
        CMBID.DataSource = ds.Tables(0)
        CMBID.DisplayMember = "EMP_ID"
        CMBID.ValueMember = "ID"
        CMBID.SelectedValue = 0
        CMBID.Invalidate()
    Catch ex As Exception
        MessageBox.Show(ex.Message)
    Finally
        Conn.Close()
    End Try
End Sub

Private Sub CMBID_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles CMBID.SelectedIndexChanged
    Dim gend As String
    getConnect()
    Dim strSQL As String = "SELECT * FROM EMPLOYEE WHERE EMP_ID=" & CMBID.Text & ""
    Try
        Dim da As SqlDataAdapter = New SqlDataAdapter(strSQL, Conn)
        Dim ds As DataSet = New DataSet
        da.Fill(ds, "EMPLOYEE")
        Dim dt As DataTable = ds.Tables("EMPLOYEE")
        Dim row As DataRow
        For Each row In dt.Rows
            ID.Text = row("ID")
            TXTNAME.Text = row("EMP_NAME")
            TXTFNAME.Text = row("EMP_FNAME")
            gend = row("EMP_GENDER")
            If gend = "MALE" Then
                RBMALE.Checked = True
                RBFEMALE.Checked = False
            ElseIf gend = "FEMALE" Then
                RBFEMALE.Checked = True
                RBMALE.Checked = False
            End If
            DTPEMPDOB.Value = row("EMP_DOB")
            TXTCASTE.Text = row("EMP_CAST")
            CMBDEPT.Text = row("EMP_DEPART")
            CMBDESIG.Text = row("EMP_DESIG")
            DTPEMPDOJ.Value = row("EMP_DOJ")
            MTXTSAL.Text = row("EMP_SALARY")
            MTXTPFESI.Text = row("EMP_PF_ESI")
            TXTBRANCH.Text = row("EMP_BRANCH")
            MTXTCONTACT.Text = row("EMP_CONTACT")
            RTXTADDRESS.Text = row("EMP_ADDRESS")
        Next row
    Catch ex As Exception
        MessageBox.Show(ex.Message)
    Finally
        Conn.Close()
    End Try
End Sub

请尝试检查我的代码并给我解决方案。

4

1 回答 1

0
    Dim strSQL As String = "SELECT * FROM EMPLOYEE ORDER BY EMP_ID ASC"
    Dim da As New SqlDataAdapter(strSQL, Conn)
    Dim ds As New DataSet
    da.Fill(ds, "EMPLOYEE")
    CMBID.DataSource = ds.Tables(0)
    CMBID.DisplayMember = "EMP_ID"
    CMBID.ValueMember = "ID"
    CMBID.SelectedValue = Nothing
    //CMBID.Invalidate()



Private Sub CMBID_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles CMBID.SelectedIndexChanged
{
  If clientComboBox.SelectedValue Is Nothing Then
Return
  End If

  If CMBID.SelectedValue.toString() = "System.Data.DataRowView" Then
Return
  End If
   //Do stuff

}
于 2013-01-15T13:53:43.280 回答