Community discussion forum

Dynamic values in SQL Query

Tags: asp.net India
  • 1 year ago

    Hi .. I want to change the  value Dynamic in SQL Query.... in the ASP.NET Page

    I have attached the Source codes.....

    1st File 

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="ConsIndex.aspx.cs" Inherits="Cons_ConsIndex"
        MasterPageFile="~/MasterPage.master" %>

    <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
        <asp:FormView ID="FormView1" AllowPaging="false" DataSourceID="sqldatasource1" Width="80%"
             runat="server">
            <ItemTemplate>
                <table align="left">
                    <tr>
                        <td>
                       
                        <a id="href1" href="consA-Z.aspx?cons=A" target="_self">                   
                            A
                            </a></td>
                        <td>
                            |</td>
                        <td>
                            <a id="A1" href="consA-Z.aspx?cons=B" target="_self">                   
                            B
                            </a></td>
                        <td>
                            |</td>
                        <td>
                            <a id="A2" href="consA-Z.aspx?cons=C" target="_self">                   
                            C
                            </a></td>
                        <td>
                            |</td>
                        <td>
                           <a id="A3" href="consA-Z.aspx?cons=D" target="_self">                   
                            D
                            </a></td>
                        <td>
                            |</td>
                        <td>
                            E</td>
                        <td>
                            |</td>
                        <td>
                            F</td>
                        <td>
                            |</td>
                        <td>
                            G</td>
                        <td>
                            |</td>
                        <td>
                            H</td>
                        <td>
                            |</td>
                        <td>
                            I</td>
                        <td>
                            |</td>
                        <td>
                            J</td>
                        <td>
                            |</td>
                        <td>
                            K</td>
                        <td>
                            |</td>
                        <td>
                            L</td>
                        <td>
                            |</td>
                        <td>
                            M</td>
                        <td>
                            |</td>
                        <td>
                            N</td>
                        <td>
                            |</td>
                        <td>
                            O</td>
                        <td>
                            |</td>
                        <td>
                            P</td>
                        <td>
                            |</td>
                        <td>
                            Q</td>
                        <td>
                            |</td>
                        <td>
                            R</td>
                        <td>
                            |</td>
                        <td>
                            S</td>
                        <td>
                            |</td>
                        <td>
                            T</td>
                        <td>
                            |</td>
                        <td>
                            U</td>
                        <td>
                            |</td>
                        <td>
                            V</td>
                        <td>
                            |</td>
                        <td>
                            W</td>
                        <td>
                            |</td>
                        <td>
                            X</td>
                        <td>
                            |</td>
                        <td>
                            Y</td>
                        <td>
                            |</td>
                        <td>
                            Z</td>
                        <td>
                            |</td>
                    </tr>
                </table>
            </ItemTemplate>
        </asp:FormView>
        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CellPadding="3"
            DataKeyNames="consid" DataSourceID="sqldatasource1" Width="100%" AllowSorting="true">
            <Columns>
                <asp:BoundField HeaderText="consid" Visible="False" />
                <asp:TemplateField SortExpression="consid">
                    <ItemTemplate>
                        <p align="left" style="font-family: Arial; font-size: small;">
                            <img src="../images/arrow.gif" border="0" width="10" height="11" />
                            <a href="Consshorttitle.aspx?<%# Eval("consid") %>">
                                <%# Eval("consname") %>
                            </a>
                        </p>
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
        </asp:GridView>
        <asp:SqlDataSource ID="sqldatasource1" runat="server" OnSelecting="AccessDataSource1_Selecting"
            ConnectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Inetpub\wwwroot\eLaw\App_Data\sampleDB.mdf;Integrated Security=True;User Instance=True"
            ProviderName="System.Data.SqlClient" SelectCommand="SELECT * FROM consindex Order by consname">
        </asp:SqlDataSource>
    </asp:Content>
    <asp:Content ContentPlaceHolderID="FooterPlaceHolder1" ID="Content2" runat="server">
    </asp:Content>

     __________________________

    In this Page i had passed the value A to Z at the Top of the Page .... 

    __________________________

    2nd Page

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="consA-Z.aspx.cs" Inherits="Cons_consA_Z"
        MasterPageFile="~/MasterPage.master" %>

    <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CellPadding="3"
            DataKeyNames="consid" DataSourceID="AccessDataSource1" Width="100%" AllowSorting="true">
            <Columns>
                <asp:BoundField HeaderText="consid" Visible="False" />
                <asp:TemplateField SortExpression="consid">
                    <ItemTemplate>
                        <table width="80%" align="center">
                            <tr>
                                <td align="left" width="3%" colspan="3">
                                </td>
                                <td align="left" width="75%">
                                    <%# Eval("consname")%>
                                </td>
                            </tr>
                        </table>
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
        </asp:GridView>
        <asp:SqlDataSource ID="AccessDataSource1" runat="server" OnSelecting="AccessDataSource1_Selecting"
            ConnectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Inetpub\wwwroot\eLaw\App_Data\sampleDB.mdf;Integrated Security=True;User Instance=True"
            ProviderName="System.Data.SqlClient" SelectCommand="SELECT * FROM consindex WHERE consname LIKE '@cons%'">
            <SelectParameters>
                <asp:QueryStringParameter Name="cons" QueryStringField="cons" Type="String" />
            </SelectParameters>
        </asp:SqlDataSource>
    </asp:Content>
    <asp:Content ContentPlaceHolderID="FooterPlaceHolder1" ID="Content2" runat="server">
    </asp:Content>

    ____________________

    In this  Page i want to change the value which i had bold and italicsed the content......

    The thing what is .. i want to get the value from the First page and to add dynamicaly in the 2nd Page

    Please help 

    ____________________

    Thanks in Advance

    VinoopRaj 

     

     

     

     

     

     

     

  • 1 year ago

    you can write

    original

    <asp:SqlDataSource ID="AccessDataSource1" runat="server" OnSelecting="AccessDataSource1_Selecting"
            ConnectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Inetpub\wwwroot\eLaw\App_Data\sampleDB.mdf;Integrated Security=True;User Instance=True"
            ProviderName="System.Data.SqlClient" SelectCommand="SELECT * FROM consindex WHERE consname LIKE '@cons%'">

    write this way

    <asp:SqlDataSource ID="AccessDataSource1" runat="server" OnSelecting="AccessDataSource1_Selecting"
            ConnectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Inetpub\wwwroot\eLaw\App_Data\sampleDB.mdf;Integrated Security=True;User Instance=True"
            ProviderName="System.Data.SqlClient" SelectCommand="SELECT * FROM consindex WHERE consname LIKE ' " & <%=request("conts")%> & "%'">

    also remove following code

    <SelectParameters>
                <asp:QueryStringParameter Name="cons" QueryStringField="cons" Type="String" />
       </SelectParameters>

     

     it will work and please update after testing

     

  • 1 year ago

    Thank u PradipPatel

    but its not valid .. the server tag is not well formed..... can u help more...

    regrds
    VinoopRaj 

     

  • 1 year ago

    Thank u PradipPatel

    but its not valid .. the server tag is not well formed..... can u help more...

    regrds
    VinoopRaj 

     

Post a reply

Enter your message below

Sign in or Join us (it's free).

We'd love to hear what you think! Submit ideas or give us feedback