VS2010中的ActiveX数据网格控件 [英] ActiveX datagrid control in VS2010

查看:121
本文介绍了VS2010中的ActiveX数据网格控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello Everyone,



我试图在VS2010中使用ActiveX数据网格控件,但有一些特殊原因。我在将数据集绑定到ActineX datgrid时遇到麻烦。 br />


以下是我写的代码。



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.

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)

//在这里失败,试图将ActiveX控件绑定到数据集





我在运行时获得以下异常:



DataGrid_Code_Example.exe中出现未处理的System.InvalidCastException类型异常



附加信息:无法转换类型为'的对象System.Data.DataTable'键入'msdatasrc.DataSource'。




请帮助我。



问候,

Joy

//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

推荐答案

你不能使用.NET DataSet / DataTable类您尝试使用的旧网格。那个网格不知道什么是.NET类,所以不能使用它。



用DataGridView替换网格,你可以将它绑定到而不是数据。



如果你真的想让自己头疼,你必须编写代码将来自数据库的数据转换成某种数据源您当前可以使用的对象。



提示,使用DGV更容易。
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.


这篇关于VS2010中的ActiveX数据网格控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆