CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Jul 2009
    Location
    Kuwait
    Posts
    170

    [RESOLVED] databinding in adodb connection

    Hi,
    I am connecting to a foxpro table using adodb connection
    Code:
     fcn = New ADODB.Connection
            fcn.ConnectionString = "provider=VFPOLEDB.1;Data Source= D:\" & shopname
            fcn.Open()
    Using this I am trying to fill a datagrid values using binding. The value of ts=0
    Code:
    rst.Open("SELECT ITEM, ORD, INVENTORY FROM INVENT Where ITEM Like '" & itemno & "' ORDER BY ITEM", fcn)
            BindingSource1.DataSource = rst
             rst.Close()
     DataGridView1.Item(17, s).Value = Format((ts / Val(rst(1).Value)), "0.00")
    But this statement is not working . I am getting follwoing error
    Code:
    Following exception occured in the datagridview
    System Exceptio: 0.00 is not a valid value for Int32. --> System.formatException: Input string was not in a correct format
    But this is working fine for OleDbConnection

  2. #2
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: databinding in adodb connection

    0.00 is not a valid value for Int32
    Tells you that one of your values says Int32, but seems to be string data
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    Join Date
    Jul 2009
    Location
    Kuwait
    Posts
    170

    Re: databinding in adodb connection

    I modified te code to
    Code:
        rst.Open("SELECT lp.ITEM, lp.ORD, INVENT." & qt1 & ", INVENT." & qt2 & ", INVENT." & qt3 & ", INVENT." & qt4 & ", INVENT." & qt5 & ", INVENT." & qt6 & ", INVENT." & qt7 & ", INVENT." & qt8 & ", INVENT." & qt9 & ", " & totquan & ", lp.PRICE, lp.CATEGORY, lp.LINE, lp.QORD FROM INVENT INNER JOIN lp ON INVENT.ITEM_NO = lp.ITEM_NO Where lp.ITEM Like '" & itemno & "' ORDER BY lp.ITEM", fcn)
            BindingSource1.DataSource = rst
    
                       rst1.Open("SELECT lp.ITEM as totitem, lp.ORD, INVENT." & qt1 & ", INVENT." & qt2 & ", INVENT." & qt3 & ", INVENT." & qt4 & ", INVENT." & qt5 & ", INVENT." & qt6 & ", INVENT." & qt7 & ", INVENT." & qt8 & ", INVENT." & qt9 & ", " & totquan & ", lp.PRICE, lp.CATEGORY, lp.LINE, lp.QORD FROM INVENT INNER JOIN lp ON INVENT.ITEM_NO = lp.ITEM_NO Where lp.ITEM Like '" & itemno & "' ORDER BY totitem", fcn)
    
                    While Not rst.EOF 
                        If IsDBNull(rst1(11).Value) = False And IsDBNull(rst1(15).Value) = False And Val(rst1(15).Value) <> 0 Then
                                                 ts = (rst1(15).Value) - (rst1(11).Value)
                   
                            ts = ts * 100
                            DataGridView1.Item(17, s).Value = Format((ts / Val(rst1(15).Value))) ', "0.00")
                        Else
                            DataGridView1.Item(17, s).Value = "No T/O"
                        End If
                        s = s + 1
                        If s > DataGridView1.RowCount Then
                            Exit While
                        End If
                        rst1.MoveNext()
                    End While
    rst1.close()
          rst.Close()
    I am getting multiple exceptions
    I have attached a screen shot of the errors
    Attached Images Attached Images  

  4. #4
    Join Date
    Jul 2009
    Location
    Kuwait
    Posts
    170

    Re: databinding in adodb connection

    I feel like the problem is with the data binding using ADODB connection.
    Code:
      fcn = New ADODB.Connection
            fcn.ConnectionString = "provider=VFPOLEDB.1;Data Source= D:\" & foldrname
            fcn.Open()
    
        rst = New ADODB.Recordset
    Last edited by makdu; December 1st, 2009 at 04:19 AM. Reason: more code included

  5. #5
    Join Date
    Jul 2009
    Location
    Kuwait
    Posts
    170

    Re: databinding in adodb connection

    The data binding done is wrong. if any one know the syntax for binding source , please let me know
    Here is what i tried with
    Code:
    fcn = New ADODB.Connection
            fcn.ConnectionString = "provider=VFPOLEDB.1;Data Source= D:\" & foldrname
            fcn.Open()
    rst = New ADODB.Recordset
    rst.open("select * from table" ,fcn)
                  BindingSource1.DataSource = rst
                    DataGridFirst.ReadOnly = True
                    DataGridFirst.DataSource = BindingSource1
    rst.Close()

  6. #6
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: databinding in adodb connection

    I have a link in my signature, showing the correct way to do it. Here: http://code.msdn.microsoft.com/vbsamples/
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  7. #7
    Join Date
    Jul 2009
    Location
    Kuwait
    Posts
    170

    Re: databinding in adodb connection

    I changed from adodb to oledb and now its working
    Code:
      newn = New OleDbConnection
            newn.ConnectionString = "provider=VFPOLEDB.1;Data Source= D:\" & shopname
            newn.Open()
    Thanks dglienna for the support provided

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured