Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > .NET > Other .NET > ADO.NET
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
ADO.NET For discussion about ADO.NET.††Topics such as question regarding the System.Data namespace are appropriate.††Questions specific to a particular application should be posted in a forum specific to the application .
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ADO.NET section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Closed Thread
 
Thread Tools Display Modes
  #1 (permalink)  
Old October 1st, 2003, 10:43 AM
Registered User
 
Join Date: Jun 2003
Location: Middleton, WI, USA.
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to kpowers@wppisys.org
Default Weird Combobox Error

Hello everyone,

I'm getting a strange error when I try to bind a combo box to a Dataset.
Here's my code!

Private Sub Get_Data()
        Try
            Dim sqlcmd = New SqlCommand("Select * from Utility order by
Utility", sqlConn)

            daDataAdapter = New SqlDataAdapter
            daDataAdapter.SelectCommand = sqlcmd

            dsDataSet = New Dataset
            daDataAdapter.Fill(dsDataSet, "Utility")


            sqlcmd = New SqlCommand("Select * from Adjustments", sqlConn)
            daDataAdapter = New SqlDataAdapter
            daDataAdapter.SelectCommand = sqlcmd

            daDataAdapter.Fill(dsDataSet, "Adjustments")

            daRel = New DataRelation("UtilAdjust",
dsDataSet.Tables("Utility").Columns("Code"),
dsDataSet.Tables("Adjustments").Columns("Code"))
            dsDataSet.Relations.Add(daRel)

            Set_Update_Command()
            Set_Insert_Command()
            Set_Delete_Command()

        Catch ex As Exception
            MessageBox.Show(ex.Source.ToString & " - " & ex.Message,
Application.ProductName, _
            MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try

    End Sub

    Private Sub BindFields()
        Try
            Dim ctrl As Control
            For Each ctrl In Me.Controls
                If TypeOf ctrl Is TextBox Then
                    ctrl.DataBindings.Clear()
                    ctrl.Text = ""
                End If
            Next

            cbUtility.DataBindings.Clear()
            cbType.DataBindings.Clear()

            For Each ctrl In Me.GroupBox1.Controls
                If TypeOf ctrl Is TextBox Then
                    ctrl.DataBindings.Clear()
                    ctrl.Text = ""
                End If
            Next

            cbUtility.DataSource = dsDataSet.Tables("Utility")
            cbUtility.DisplayMember = "UTILITY"
            cbUtility.ValueMember = "CODE"



            tbAN.DataBindings.Add("Text", dsDataSet,
"Utility.UtilAdjust.AdjustmentName")
            lblAK.DataBindings.Clear()
            lblAK.DataBindings.Add("Text", dsDataSet,
"Utility.UtilAdjust.AdjKey")

            BindDate(tbASD, "UTILITY.UtilAdjust.AdjStartDate")
            BindDate(tbAED, "UTILITY.UtilAdjust.AdjEndDate")

            BindCurr(tbAA, "UTILITY.UtilAdjust.adjustment")

            BindType(cbType, "UTILITY.UtilAdjust.type")

            bmUtil = Me.BindingContext(dsDataSet, "Utility")
            bmAdjust = Me.BindingContext(dsDataSet, "UTILITY.UtilAdjust")

            AddHandler Me.BindingContext(dsDataSet,
"Utility").PositionChanged, _
            AddressOf dtUtil_PositionChanged

        Catch ex As Exception
            MessageBox.Show(ex.Source.ToString & " - " & ex.Message,
Application.ProductName, _
            MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
    End Sub


First I get my data by calling Get_Data(), Next I bind my data be calling
BindFields()

I get the following error when I hit these statements. cbUtility = combo
box = System.Windows.Forms.ComboBox
cbUtility.DataSource = dsDataSet.Tables("Utility")
cbUtility.DisplayMember = "UTILITY"


Error:
"Microsoft.VisualBasic - Cast from type 'DataRowView' to type 'String' is
not valid"

Another odd thing is when the exception is raised my "Catch" doesn't pick
it
up! I get an error message on those lines and the program keeps going? Also everything works correctly, all controls are bound correctly,
including
that combo box.

THanks,
Closed Thread


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Weird Error Message jeremy1048 Access 2 April 8th, 2008 04:52 AM
Weird Syntax Error mjhoagland Classic ASP Professional 3 May 5th, 2007 04:25 AM
VWD Weird Error bmains Visual Studio 2005 1 May 2nd, 2005 09:46 AM
Weird MySQL error cmiller PHP Databases 3 April 6th, 2004 04:08 AM



All times are GMT -4. The time now is 08:36 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.