| |

VerySource

 Forgot password?
 Register
Search
View: 695|Reply: 2

Masters help me see how to correct this error

[Copy link]

2

Threads

8

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 China

Post time: 2020-3-18 17:30:01
| Show all posts |Read mode
I used it first: Dim binds As BindingSource = New BindingSource
        Dim dt As DataTable = New DataTable
        Dim da As Odbc.OdbcDataAdapter
        Dim Conn As New Odbc.OdbcConnection
        Conn = Me.comm.DBopen ()
        da = New Odbc.OdbcDataAdapter (sSelectCmd, Conn)
        da.Fill (dt)
        binds.DataSource = dt
        Me.DgViewReportCode.DataSource = binds
        Me.BindingNavReportCode.BindingSource = bind
************************************************** *******
And then used it in another process
           Dim dt1 As DataTable = New DataTable ()
             dt1 = Me.DgViewReportCode.DataSource '' 'Error reported here
                    IsPaste = False
                    dt1.AcceptChanges ()
 The error is: "Cannot convert System.Windows.Forms.BindingSource type to System.Data.DataTable type"

Why is it reporting such a mistake ... how to change it ????
(If I block the above *, the following is correct, but I cannot block any code above)
Reply

Use magic Report

1

Threads

9

Posts

8.00

Credits

Newbie

Rank: 1

Credits
8.00

 China

Post time: 2020-6-26 18:45:01
| Show all posts
When you use the DataAdapter object to fill it, you should use the data set instead of the table. Modify it to the following:
Dim binds As BindingSource = New BindingSource
        Dim ds As DataTable = New DataSet
        Dim da As Odbc.OdbcDataAdapter
        Dim Conn As New Odbc.OdbcConnection
        Conn = Me.comm.DBopen()
        da = New Odbc.OdbcDataAdapter(sSelectCmd, Conn)
        da.Fill(ds)
        binds.DataSource = ds.Tables(0)
        Me.DgViewReportCode.DataSource = binds
        Me.BindingNavReportCode.BindingSource = bind

Another process uses:
           Dim dt1 As DataTable = New DataTable()
             dt1 = Me.DgViewReportCode.DataSource
                    IsPaste = False
                    dt1.AcceptChanges()
Reply

Use magic Report

2

Threads

8

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 China

 Author| Post time: 2020-7-8 15:15:01
| Show all posts
Thanks to the brother upstairs for answering...

  But if you change this way, you still get the same error
   dt1 = Me.DgViewReportCode.DataSource

   The type of dt1 is "System.Data.DataTable",
  The type of Me.DgViewReportCode.DataSource is "System.Windows.Forms.BindingSource"

  These two don't match...the conversion can't come.........


  What should I change...?
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list