Click here to Skip to main content
15,891,657 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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()


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()


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.
Posted
Updated 16-Jul-15 2:22am
v2

1 solution

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
 
Share this answer
 
Comments
[no name] 16-Jul-15 8:43am    
I am googling from many hours, there are many examples and other ways to do this task but i want to do this according to my mentioned way. I know this is too old but i still like it and using it every where. If you can do please solve it.
F-ES Sitecore 16-Jul-15 8:50am    
You mean you *want* to use ADODB? Just learn ado.net, it's not that hard. .net components like the grid view uses .net interfaces like IEnumerable etc that ADODB components don't support as they are just .net wrappers around COM objects.
[no name] 16-Jul-15 8:55am    
I know data adapter, data sets and data fill techniques but i don,t know why i still like adodb. May be this is due to too much practice in adodb. Is there any technology which is modern but like adodb?
F-ES Sitecore 16-Jul-15 9:06am    
Yes, ado.net. What you are using is "ADO", not "ADO.net" - ADO is the COM version and ADO.net the .net version.
[no name] 16-Jul-15 9:15am    
You wrote above this "System.Data.SqlClient.SqlConnection". Does this ado.net or only ado.

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