• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 197
  • Last Modified:

Why do i get this value returned

Hi All.
Programming in VS.NET using VB.NET Windows Forms

Have the following code on a combobox (call it the parent)
Private Sub adRE_cmbRaceName_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles adRE_cmbRaceName.SelectedIndexChanged

        LoadDate()

    End Sub

it calls this function to load the 'child' combobox with values from the DB


Private Function LoadDate() As Integer
        Dim myDS As New DataSet
        Dim cnn As SqlConnection = New SqlConnection(ClientConnString)
        Dim myCommand As SqlCommand = New SqlCommand("Select RaceDate from race_event where RaceID = " & adRE_cmbRaceName.SelectedValue, cnn)
        myCommand.CommandType = CommandType.Text
        cnn.Open()

        Dim myDataAdapter As SqlDataAdapter = New SqlDataAdapter(myCommand)
        Try
            myDataAdapter.Fill(myDS, "Date")
        Catch
            MsgBox("Error updating database. Error number: " & Err.Number & ": Description: " & Err.Description, MsgBoxStyle.Exclamation, "Database Error")
        End Try

        cnn.Close()

        adRE_cmbRaceDate.DataSource = myDS.Tables(0)
        adRE_cmbRaceDate.DisplayMember = "RaceDate"

    End Function

All code works fine but everytime the child combobox is filled with the following text only, 'System.Data.DataRowView'.
Then i move the parent again, it fires the code, and i get the values i want in the child. This happens on all my combo boxes i do on a selectediindexchange trigger so hopefully someone has seen this before as i am pulling my hair out. Won't do to have to tell the user to 'Just twiddle with the drop-downs until the values come out' LOL.

Thanks everyone!!





0
Winston Smith
Asked:
Winston Smith
1 Solution
 
khan_zahid20Commented:
'hey brother try this out

' drag and drop two combobox 1) combobox1 2) combobox2


 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Dim myDS As New DataSet
        Dim cnn As SqlConnection = New SqlConnection("Server=localhost;uid=sa;pwd=;database=northwind")
        Dim myCommand As SqlCommand = New SqlCommand("Select customerid from customers", cnn)

        cnn.Open()

        Dim myDataAdapter As SqlDataAdapter = New SqlDataAdapter(myCommand)
        Try
            myDataAdapter.Fill(myDS, "Date")
        Catch
            MsgBox("Error updating database. Error number: " & Err.Number & ": Description: " & Err.Description, MsgBoxStyle.Exclamation, "Database Error")
        End Try

        cnn.Close()
        Dim i As Integer
        For i = 0 To myDS.Tables(0).Rows.Count - 1
            ComboBox1.Items.Add(myDS.Tables(0).Rows(i)("customerid"))
        Next

combobox1.selectedindex = 0
    End Sub


    Private Function LoadDate() As Integer
        Dim myDS As New DataSet
        Dim cnn As SqlConnection = New SqlConnection("Server=localhost;uid=sa;pwd=;database=northwind")
        Dim myCommand As SqlCommand = New SqlCommand("Select companyname from customers where customerid ='" & ComboBox1.SelectedItem & "'", cnn)
        myCommand.CommandType = CommandType.Text
        cnn.Open()

        Dim myDataAdapter As SqlDataAdapter = New SqlDataAdapter(myCommand)
        Try
            myDataAdapter.Fill(myDS, "Date")
        Catch
            MsgBox("Error updating database. Error number: " & Err.Number & ": Description: " & Err.Description, MsgBoxStyle.Exclamation, "Database Error")
        End Try

        cnn.Close()

        ComboBox2.DataSource = myDS.Tables(0)
        ComboBox2.DisplayMember = "companyname"

End Function

    Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
        LoadDate()
    End Sub
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now