• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 489
  • Last Modified:

C# Question about query results

Here is the code.  This question is specifically about the SQL portion of the code:
<%@ Page Title="" Language="C#" MasterPageFile="~main.master" %>
 <script runat="server">

protected void btnAdd_Click(object sender, EventArgs e)
    txtNewBook.Text = String.Empty;
 <asp:Content ID="Content2" ContentPlaceHolderID="cphMain" Runat="Server">
 <div id="awindow" >
<asp:Panel ID="Panel1" runat="server" CssClass="mainContent">
<div style="width: 100%; float: left">    
    <asp:Image ID="Image1" runat="server" ImageUrl=" "  Width="100%"/>
    <asp:TextBox runat="server"  style="margin-left:5px; float:left;" ID="txtNewTitle" />
    <asp:ImageButton runat="server" ID="btnAddTitle" Height="17px" ToolTip="Add New Book"      ImageUrl="~insert.png" OnClick="btnAd_Click"/>
<asp:SqlDataSource runat="server" ID="sqlBookLibs" ConnectionString="<%$   ConnectionStrings:dbbooks %>" ProviderName="<%$ ConnectionStrings:AllBooks.ProviderName %>" 
    SelectCommand="SELECT * FROM BookTitles ORDER BY Titles" 
    InsertCommand="BookTitles_GetOrCreate" InsertCommandType="StoredProcedure">
        <asp:ControlParameter ControlID="txtNewTitle" Name="titlename" />

    <asp:GridView runat="server" ID="gvBooks" DataSourceID="sqlBookTitles" DataKeyNames="BookTitles" AutoGenerateColumns="false">
            <asp:HyperLinkField HeaderText="Book Name"  DataNavigateUrlFormatString="~/BookTitles/Books.aspx?id={0}" DataNavigateUrlFields="PartnerID" DataTextField="BookName" />
             <asp:HyperLinkField HeaderText="Find Book Titles"  DataNavigateUrlFields="" DataTextField="" />


Open in new window

My question is- shouldn't I be able to use the result of the above SQL query in other text boxes, drop down boxes, and text areas I include on this page without re-running the query?  

If so, wouldn't I do that by just referencing the ID in the textbox or text area?  

(Ex:  <input type="text" name="New Title" ID="SQLBookLibs"/>
1 Solution
1: You can try calling the SqlDataSource.Select manually and store the return values in a local datatable: http://stackoverflow.com/questions/9452763/convert-sqldatasource-to-datatable-and-dataview
2: Do not use SqlDataSource and manually call Select and Insert using sqlCommand:
programmherAuthor Commented:
Thank you Guru_Sami.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

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.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now