vb.net, web page, SQL holding the selected data in an accessible variable

The following code works, but I did not like because in order to get selected sql data I have to add a gridview control!!
Is there a way to get the returned data in a variable

         <asp:SqlDataSource ID="sourcename" runat="server" ConnectionString="<%$ ConnectionStrings:constr %>">            
         </asp:SqlDataSource>
         <%  
             sourcename.SelectParameters.Add("CustIdIs", Session("CustIdIs"))
             sourcename.SelectCommand = "SELECT Col1, col2 FROM Table WHERE Col0= @CustIdIs  "
          %>
         <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="sourcename">
             <Columns>
                 <asp:BoundField DataField="Col1" HeaderText="Txt1" SortExpression="ttt" />                
                 <asp:BoundField DataField="Col2" HeaderText="Txt2" SortExpression="ttt" />                
            </Columns>
         </asp:GridView>
<%
            Dim I
            Dim str As String

            For I = 1 To GridView1.Rows.Count - 1
                str = GridView1.Rows(I).Cells(0).Text
                Response.Write(str & "<br>")
           Next
saljasAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Nitin SontakkeDeveloperCommented:
How many rows you are getting returned? If you will always get one row, you can use two text-boxes instead. Variable is fine, but you will loose it's contents due to the statelessness of web applications. You will probably have to store it in Session or fetch it again from db.
0
Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
but I did not like because in order to get selected sql data I have to add a gridview control!!
Is there a way to get the returned data in a variable
yes, this is really simple, if you just want to read the data, to make things easier, you probably can start by using a data command object with a data reader object, depending on what backend database are you using.
0
Prakash SamariyaIT ProfessionalCommented:
You can use SqlDataSource's Select Method in code-behind to get the data from sqldatasource as DataView and then you can play with it!
Example:
 DataView dv = (DataView)SqlDataSource1.Select(DataSourceSelectArguments.Empty);

Open in new window

Please check URL for more information: https://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.sqldatasource.select(v=vs.110).aspx
0
Build an E-Commerce Site with Angular 5

Learn how to build an E-Commerce site with Angular 5, a JavaScript framework used by developers to build web, desktop, and mobile applications.

saljasAuthor Commented:
Many thanks for your answers

Nitin Sontakke
Large number of rows

Ryan Chong
I just started using onload event which seems easyer and lest restrictions

Prakash Samariya
I have spend 3 weeks trying that and other things



It is very good idea if there is a command that gets data from sql to a variable directly e.g.
variable = "SELECT Col1, col2 FROM Table WHERE Col0= @CustIdIs  "

or some thing similer
0
Prakash SamariyaIT ProfessionalCommented:
It is very good idea if there is a command that gets data from sql to a variable directly e.g.
variable = "SELECT Col1, col2 FROM Table WHERE Col0= @CustIdIs  "
@saljas, There is no direct way to get data from any datasource to so called variable! You have to do some stuff in code-behind!

You can use
var sqlDataSourceView = SqlDataSource1.GetView(String.Empty)

Open in new window


Please check below url for SqlDataSource related all what you need!
https://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.sqldatasource(v=vs.110).aspx#Examples
0
Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
I just started using onload event which seems easyer and lest restrictions
well, onload event tells us when /where you want to execute your scripts, but it didn't mean that it's easier and less restrictions. you need a good approach how you want to extract your data, which some of us already provided that.

let us know if you need further assistance.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
saljasAuthor Commented:
could not find a solution
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.