Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

convert sqlreader to datatable

Posted on 2008-10-29
11
Medium Priority
?
894 Views
Last Modified: 2011-10-03
i have a function in a class that return rs which is defined as
dim rs as sqldatareader
rs= objcmd.executereader()
return rs

then i call the function in the default.aspx.vb page  and let the table load the rs.
table1.load(rs)

but i can't do it. it keeps saying that table1.load(rs) --expression does not produce value.
could some one helps me figure this out. i want the number of columns and rows to be dynamic. thank you.
0
Comment
Question by:StewSupport
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
  • 3
11 Comments
 
LVL 6

Expert Comment

by:AmarIs26
ID: 22831316
0
 
LVL 6

Expert Comment

by:AmarIs26
ID: 22831325
note that the above code is in c# but converting it to vb should be very easy.
0
 
LVL 60

Expert Comment

by:Kevin Cross
ID: 22831554
You can use a SqlDataAdapter with the command object instead and then just use the data adapter method .Fill(DataTable) method.

Or you can build your DataTable objects structure and then do it manually like this:

Dim sqlDR As SqlDataReader = GetDataReader(cmd)
           
            While sqlDR.Read()
                'Update data table columns with specific sqlDR("ColumnName") value
            End While

            sqlDR.Close()
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 60

Expert Comment

by:Kevin Cross
ID: 22831566
Sorry for duplication of what Amarls26 may have said, I had this typed in and got distracted and just hit enter. :)  Hopefully it is still of some use to you.
0
 

Author Comment

by:StewSupport
ID: 22831635
i have to use store procedure and then returns the data that is why i use reader then convert to table to put it into a tool that use tool1.datasource = table

otherwise i would have used adapter.
i tried to modified Amarls26  code on that link he gave but it deson't work and it doesnt even see  DataUtils.DataReaderAdapter
0
 
LVL 6

Expert Comment

by:AmarIs26
ID: 22831834
I have converted the code to vb.net it should work. I have not tested it but it compiles fine.
you should just be able to do
datatable = DataReaderAdapter . GetDataReader(existingdatareader)
0
 

Author Comment

by:StewSupport
ID: 22831969
this doesnt work. no such datareaderadapter found
0
 
LVL 6

Expert Comment

by:AmarIs26
ID: 22832049
Have you copied the code (DataReaderAdapter class)  i have written and put that in your project?

 
0
 

Author Comment

by:StewSupport
ID: 22832061
i have dones this before and it worked fine
Dim rs As SqlDataReader = AllFunctions.get_name(Name)
Dim dtreport As Data.DataTable = New Data.DataTable
                dtreport.Load(rs)

but somehow it doesn't work now. lol i got to find out why
0
 

Accepted Solution

by:
StewSupport earned 0 total points
ID: 22832113
omg i'm so stupid.
i put these two lines together and make it not work.
gridview.datasource = dt.load(rs)
instead of
dt.load(rs)
gridview.datasource = dt
0
 
LVL 60

Expert Comment

by:Kevin Cross
ID: 22833428
Nice one!  Don't use the DataTable.Load function much, but I should. :) I like using the generic DataTable and DataRow in code and hide the database details in data layer...Glad you found it.

Since DataTable.Load is a sub, I would think having two lines approach was more appropriate.

What you found that works suggested it is acting as though that is a function that returns DataTable or interface accepted by datasource. :) Very interesting.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question