Not getting the value l_no cmd.Parameters.AddWithValue("@l_no", l_no);


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: Not getting the value l_no cmd.Parameters.AddWithValue("@l_no", l_no);

  1. #1
    Join Date
    Oct 2011
    Posts
    2

    Not getting the value l_no cmd.Parameters.AddWithValue("@l_no", l_no);

    Code:
        protected void l_no_Click(object sender, EventArgs e)
        {
            // Fetch the customer id
            LinkButton lb = sender as LinkButton;
            string custID = lb.Text;
            lblCustValue.Text = custID;
            // Connection
            string constr = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["JAPITConnectionString"].ConnectionString;
            string sql = "SELECT * FROM Letter_dept WHERE l_no= @l_no";
            SqlConnection connection = new SqlConnection(constr);
            connection.Open();
            SqlCommand cmd = new SqlCommand(sql, connection);
            cmd.Parameters.AddWithValue("@l_no", l_no);
            cmd.CommandType = CommandType.Text;
            
            SqlDataReader dr = cmd.ExecuteReader();
            // Bind the reader to the GridView
            // You can also use a lighter control
            // like the Repeater to display data
            GridView2.DataSource = dr;
            GridView2.DataBind();
            connection.Close();
            // Show the modalpopupextender
            ModalPopupExtender1.Show();
    
        }
    Code:
    <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    
    <asp:ScriptManager ID="ScriptManager1" runat="server">
                    </asp:ScriptManager>
       
     
    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
    <ContentTemplate>
    
    <asp:GridView ID="GridView1" runat="server" 
    AutoGenerateColumns="False" AllowPaging="True" DataSourceID="SqlDataSource1" 
            onselectedindexchanged="GridView1_SelectedIndexChanged" >
               <Columns>
               
                <asp:TemplateField HeaderText="l_no">
                       <ItemTemplate>
                       <asp:LinkButton  runat="server" ID ="l_no"  Text='<%# Eval("l_no") %>' OnClick="l_no_Click" />
                       </ItemTemplate>
                       </asp:TemplateField>
                  
                   <asp:BoundField DataField="nam_dep" HeaderText="nam_dep" 
                       SortExpression="nam_dep" />
                   <asp:BoundField DataField="no_deo" HeaderText="no_deo" 
                       SortExpression="no_deo" />
                   <asp:BoundField DataField="no_mon" HeaderText="no_mon" 
                       SortExpression="no_mon" />
                   <asp:BoundField DataField="le_yn" HeaderText="le_yn" 
                       SortExpression="le_yn" />
                           
                      
                       
                       
                  
                   <asp:BoundField DataField="dd_yn" HeaderText="dd_yn" SortExpression="dd_yn" />
               </Columns>
               </asp:GridView>
    <asp:ModalPopupExtender ID="ModalPopupExtender1" runat="server"
        TargetControlID="btnShowModalPopup"
        PopupControlID="divPopUp"
        BackgroundCssClass="popUpStyle"
        PopupDragHandleControlID="panelDragHandle"
        DropShadow="true">   </asp:ModalPopupExtender>
    <asp:Button runat="server" ID="btnShowModalPopup" style="display:none"/>
            <div class="popUpStyle"  id="divPopUp"  style="display:none;">
        <asp:Panel runat="Server" ID="panelDragHandle" CssClass="drag">
            Hold here to Drag this Box
        </asp:Panel>
        <asp:Label runat="server" ID="lblText" Text="CustomerID: "></asp:Label>
        <asp:Label ID="lblCustValue" runat="server"></asp:Label>
        <asp:GridView ID="GridView2" runat="server">
        </asp:GridView>                         
        <asp:Button ID="btnClose" runat="server" Text="Close" />
       <br />
    </div>       
        
    </ContentTemplate>
        </asp:UpdatePanel>  
       <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
            ConnectionString="<%$ ConnectionStrings:JAPITConnectionString %>" 
            SelectCommand="SELECT * FROM [viewyn]"></asp:SqlDataSource>
    </asp:Content>

  2. #2
    Join Date
    Oct 2008
    Posts
    142

    command parameters

    hi there,

    i recommend the following to this task of creating a command parameter:

    Code:
    cmd.Parameters.Add("@l_no", SqlDbType.Int, 4).Value = <l_no value>
    which means you have to declare the data type of this parameter. sometimes, you also need the direction (input or output). in this example, the size of this parameter is also specified. you might skip this if your datatype is varchar.

    besides, in your code i don't see l_no variable receiving any value.

    good luck,

    tonci korsano

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center