Hello Every One,

When i run my project i get Error "There is no row at position 0", please help.

Here is my code:

Private Sub PopulateDepartmentHead()

        'Fill data in comboBox
        Dim SqlDataAdapter As OleDbDataAdapter
        Dim DSet As New DataSet
        Dim strSelect As String
        SQLConn.Close()
        SQLConn.ConnectionString = oFunc.GetConnectionString(sINIFile)
        'myConn = New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=" & strPath & "\" & strName & ".mdf" & ";Integrated Security=True;User Instance=True")
        SQLConn.Open()

        Try
            strSelect = "SELECT * FROM dbo.hrEmployeeInformation"
            SqlDataAdapter = New OleDbDataAdapter(strSelect, SQLConn)
            DSet = New DataSet()
            SqlDataAdapter.Fill(DSet)
            Me.dhcboEmployeeSelect.DataSource = DSet.Tables(0)
            Me.dhcboEmployeeSelect.ValueMember = "eiEmployeeID"
            Me.dhcboEmployeeSelect.DisplayMember = "eiFirstName"
            'MsgBox(Me.dhcboEmployeeSelect.DisplayMember = "Cust_ID")
            SQLConn.Close()
        Catch ex As Exception
            MessageBox.Show("Error No : " & Err.Number & vbCrLf _
                          & "Error : " & ex.Message & vbCrLf _
                          & "Source : " & Err.Source & vbCrLf _
                          , "System Message", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
    End Sub

Code for selectindexchanged event:

Private Sub dhcboEmployeeSelect_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles dhcboEmployeeSelect.SelectedIndexChanged
        Dim SqlDataAdapter As OleDbDataAdapter
        Dim custDataset As New DataSet
        Dim strSelect As String
        SQLConn.Close()
        SQLConn.ConnectionString = oFunc.GetConnectionString(sINIFile)
        SQLConn.Open()

        Try
            strSelect = "SELECT * FROM dbo.hrEmployeeInformation WHERE eiEmployeeID = '" & dhcboEmployeeSelect.Text & "'"
            SqlDataAdapter = New OleDbDataAdapter(strSelect, SQLConn)
            custDataset = New DataSet()
            SqlDataAdapter.Fill(custDataset, "dbo.hrEmployeeInformation")
            SqlDataAdapter.Dispose()
            Dim custTable As DataTable = custDataset.Tables(0)

            dhEmployeeID.Text = custTable.Rows(0).Item(0)
            dhEmployeeName.Text = custTable.Rows(0).Item(1)

            SQLConn.Close()
        Catch ex As Exception
            MessageBox.Show(ex.Message)
            SQLConn.Close()
        End Try
    End Sub

Code for Form Load:

Private Sub frmDepartmentHead_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Try
            SQLConn.Close()
            SQLConn.ConnectionString = oFunc.GetConnectionString(sINIFile)
            FormName()
            EnableControlsFormLoad(True)
            SQLConn.Open()
            ds.Clear()
            SQLConn.Close()
            'Fill Combo
            PopulateDepartmentHead()
        Catch ex As Exception
            MessageBox.Show("Error No : " & Err.Number & vbCrLf _
                          & "Error : " & ex.Message & vbCrLf _
                          & "Source : " & Err.Source & vbCrLf _
                          , "System Message", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
    End Sub

PLEASE HELP ME, WHERE DID I WENT WRONG....

Thanks

Edited 3 Years Ago by deceptikon: Fixed formatting

Most likely your query is failing to retrieve any rows.

strSelect = "SELECT * FROM dbo.hrEmployeeInformation WHERE eiEmployeeID = '" & dhcboEmployeeSelect.Text & "'"

Is "eiEmployeeID" stored as text or is it a number? If it is a number, remove the single quote (') from the the Select statement.

Thanks a lot. I have solved the problem with following code.

Private Sub dhcboEmployeeSelect_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles dhcboEmployeeSelect.SelectedIndexChanged
        Dim SqlDataAdapter As OleDbDataAdapter
        Dim custDataset As New DataSet
        Dim strSelect As String
        SQLConn.Close()
        SQLConn.ConnectionString = oFunc.GetConnectionString(sINIFile)
        SQLConn.Open()

        Try
            strSelect = "SELECT * FROM dbo.hrEmployeeInformation WHERE eiEmployeeID = '" & dhcboEmployeeSelect.SelectedValue.ToString & "'"
            SqlDataAdapter = New OleDbDataAdapter(strSelect, SQLConn)
            custDataset = New DataSet()
            SqlDataAdapter.Fill(custDataset, "dbo.hrEmployeeInformation")
            SqlDataAdapter.Dispose()
            Dim custTable As DataTable = custDataset.Tables(0)

            If custTable.Rows.Count > 0 Then
                dhEmployeeID.Text = custTable.Rows(0).Item(0)
                dhEmployeeName.Text = custTable.Rows(0).Item(2)
            End If

            SQLConn.Close()
        Catch ex As Exception
            MessageBox.Show(ex.Message)
            SQLConn.Close()
        End Try
    End Sub

Edited 3 Years Ago by tashee2007

This question has already been answered. Start a new discussion instead.