Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Everyone,

I am trying to use ActiveX datagrid control in VS2010 becuase of some specific reason.I am facing troubles while binding dataset to ActineX datgrid.

Below is the code that i have written.

VB
Dim connection As SqlConnection = New SqlConnection()
        connection.ConnectionString = "Data Source=(local);Initial Catalog=LabDetails;Integrated Security=True;"
        connection.Open()
        Dim adp As SqlDataAdapter = New SqlDataAdapter _
        ("select * from Lab", connection)
        Dim ds As DataSet = New DataSet()
        adp.Fill(ds)

        'DataGridView1.DataSource = ds.Tables(0) // This line of code is working fine with default datagrid


        AxDataGrid1.DataSource = ds.Tables(0)
//fails here, trying to bind ActiveX control here to dataset


I get below exception at run time:

An unhandled exception of type 'System.InvalidCastException' occurred in DataGrid_Code_Example.exe

Additional information: Unable to cast object of type 'System.Data.DataTable' to type 'msdatasrc.DataSource'.


Please help me.

Regards,
Joy
Posted

1 solution

You can't use the .NET DataSet/DataTable classes with the old grid you're trying to use. That grid has no idea what a .NET class is and, so, can't use it.

Replace the grid with a DataGridView and you can bind that to the data instead.

If you really want to give yourself a large headache, you'll have to write code to convert the data coming from your database to some kind of DataSource object that your current will be able to use.

Hint, it's easier to just use the DGV.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900