?
Solved

Why do i get  this value returned

Posted on 2005-03-07
1
Medium Priority
?
196 Views
Last Modified: 2010-08-05
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
Comment
Question by:Halon
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 

Accepted Solution

by:
khan_zahid20 earned 500 total points
ID: 13484685
'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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month10 days, 19 hours left to enroll

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question