textbox binding problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kpeeroo
    New Member
    • Sep 2008
    • 12

    textbox binding problem

    hi

    i am having a runtime error when am trying to bind a textbox to a column in my data table. Error is ArgumentExcepti on. Here is my code, basically am querying database to get price and date where date is placed in a combobox and i want price to be displayed in the textbox. Any idea?
    Code:
    Try
                selectedSiteName = SiteNameCBox.SelectedValue.ToString
                selectedCategory = CategoryCBox.SelectedValue.ToString
                companyName = companyNameTBox.Text
                selectedRoute = companyRouteCBox.SelectedValue.ToString
                Console.WriteLine("e " + selectedRoute)
                SqlDADate.SelectCommand.Parameters("@Param1").Value = selectedSiteName
                SqlDADate.SelectCommand.Parameters("@Param2").Value = selectedCategory
                SqlDADate.SelectCommand.Parameters("@Param3").Value = companyName
                SqlDADate.SelectCommand.Parameters("@Param4").Value = selectedRoute
                SqlDADate.Fill(objDataTable)
                CompanyDateCBox.DataSource = objDataTable
                CompanyDateCBox.DisplayMember = "Date"
                CompanyDateCBox.ValueMember = "Date"
    companyPriceTBox.DataBindings.Add("Text", objDataTable, "Price")
    Last edited by Frinavale; Oct 9 '08, 06:10 PM. Reason: added [code] tags
  • nateraaaa
    Recognized Expert Contributor
    • May 2007
    • 664

    #2
    Please post the exception information.

    Nathan

    Comment

    • kpeeroo
      New Member
      • Sep 2008
      • 12

      #3
      Thanx Nathan for the reply

      The error is :

      A first chance exception of type 'System.Argumen tException' occurred in System.Windows. Forms.dll

      Comment

      • Plater
        Recognized Expert Expert
        • Apr 2007
        • 7872

        #4
        Well since you are getting an exception, it should be easy enough to get the line number (it tells you in the stack trace) and you can figure out why there is an argument exception there?

        Comment

        • kpeeroo
          New Member
          • Sep 2008
          • 12

          #5
          am using vb.net 2008 EE and when i look at the Call Stack window during runtime, it doesnt show me any stack trace? am i missing something there? i have my line numbers displayed in the editor though.

          Comment

          • kpeeroo
            New Member
            • Sep 2008
            • 12

            #6
            sorry about that ... that stack trace gives me this:

            A first chance exception of type 'System.Argumen tException' occurred in System.Windows. Forms.dll
            at System.Windows. Forms.ControlBi ndingsCollectio n.CheckDuplicat es(Binding binding)
            at System.Windows. Forms.Binding.C heckBinding()
            at System.Windows. Forms.Binding.S etBindableCompo nent(IBindableC omponent value)
            at System.Windows. Forms.ControlBi ndingsCollectio n.AddCore(Bindi ng dataBinding)
            at System.Windows. Forms.ControlBi ndingsCollectio n.Add(String propertyName, Object dataSource, String dataMember, Boolean formattingEnabl ed, DataSourceUpdat eMode updateMode, Object nullValue, String formatString, IFormatProvider formatInfo)
            at System.Windows. Forms.ControlBi ndingsCollectio n.Add(String propertyName, Object dataSource, String dataMember)
            at WindowsApplicat ion1.Form1.comp anyRouteCBox_Se lectedIndexChan ged(Object sender, EventArgs e) in C:\Documents and Settings\Root\M y Documents\Visua l Studio 2008\Projects\W indowsApplicati on1\WindowsAppl ication1\Form2. vb:line 238

            Comment

            • Plater
              Recognized Expert Expert
              • Apr 2007
              • 7872

              #7
              Well ok I guess that doesn't work after all, the exception is occuring in their code and not in yours.
              Possibly the bindingsource is either null, or maybe does not contain an entry that it thinks it should? Like a case mismatch?
              You tell the binding source to look for say like "myTextbox" but your object is called "myTextBox" or something?
              I'm reaching on this.

              Comment

              • kpeeroo
                New Member
                • Sep 2008
                • 12

                #8
                you mean my code has got an error? i thought vb was not case sensitive? i forgot to mention that i get only the first result in my data table shown in my textbox to display the price. When i do another selection in my combo then the exception results! NULL somewhere or something?

                Comment

                • Plater
                  Recognized Expert Expert
                  • Apr 2007
                  • 7872

                  #9
                  Do you check for a selectedindex of -1 (happens when nothing is selected, and happens when you change datasources sometimes)

                  Comment

                  • kpeeroo
                    New Member
                    • Sep 2008
                    • 12

                    #10
                    no actually i didnt check for that maybe thats why its throwing an exception somewhere...let me do a check for that and see what it gives

                    Comment

                    Working...