在asp.net中使用ado的Gridview数据源问题 [英] Gridview data source problem with ado in asp.net

查看:71
本文介绍了在asp.net中使用ado的Gridview数据源问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我添加了参考Microsoft ActiveX Data Objects 6.1 Library并在我的asp.net页面中添加了GridView1控件和一个button1。在按钮中我把下面的代码。



I added reference Microsoft ActiveX Data Objects 6.1 Library and add GridView1 control and one button1 in my asp.net page. In button i put below code.

Dim res As New ADODB.Recordset
      res.Open("Select * from Table1", con, ADODB.CursorTypeEnum.adOpenDynamic, ADODB.LockTypeEnum.adLockOptimistic)

      GridView1.DataSource = res.Fields()
      GridView1.DataBind()





当我点击button1时,它会出现此错误具有id'GridView1'的GridView的数据源没有任何属性或属性可以从中生成确保您的数据源包含内容。



我想将res记录显示到GridView中而不使用任何循环,就像我想要的那样





When i click on button1, it gives this error "The data source for GridView with id 'GridView1' did not have any properties or attributes from which to generate columns. Ensure that your data source has content".

I want to show res records into GridView without using any loop like i want like this

dbconn = New OleDbConnection("Provider=SQLOLEDB.1;Persist Security Info=False;User ID=rizwan;Password=censored;Initial Catalog=chattha;Data Source=chattha.mssql.somee.com,1433")
        dbconn.Open()
        sql = "SELECT * FROM Users"
        dbcomm = New OleDbCommand(sql, dbconn)
        dbread = dbcomm.ExecuteReader()
        Table1.DataSource = dbread
        Table1.DataBind()
        dbread.Close()
        dbconn.Close()





以上代码数据从dbread转移到Table1而不使用任何循环。如果GridView使用ado,有没有办法做到这一点。



In above code data transfered from dbread to Table1 without using any loop. Is there any way to do like this in case of GridView usin ado.

推荐答案

谷歌绑定网格视图ado.net,你会发现成千上万的例子。不应该使用您引用的ADO项目(ADODB命名空间),这是十多年前的技术。而是使用在Systen.Data.dll中找到的System.Data.SqlClient.SqlConnection等
Google "bind grid view ado.net" and you'll find thousands of examples. The ADO project you have referenced shouldn't be used (the ADODB namespace), that is technology well over a decade old. Instead use the likes of System.Data.SqlClient.SqlConnection etc. as found in Systen.Data.dll


这篇关于在asp.net中使用ado的Gridview数据源问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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