必须声明标量变量

必须声明标量变量

本文介绍了必须声明标量变量“@ username”。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ASP.code

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1" Width="624px" CssClass="grid"
            AllowPaging="True" AllowSorting="True" BackColor="White"  OnRowEditing="GridView1_RowEditing" OnRowCancelingEdit="GridView1_RowCancelingEdit"
            BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" CellPadding="3" PageSize = "5"
            OnRowUpdating="GridView1_RowUpdating" DataKeyNames="id">

                <columns>
                <asp:TemplateField>
                <itemtemplate>
                <asp:CheckBox ID="chkchild" runat="server" AutoPostBack="true" />
                </itemtemplate>

                 <asp:TemplateField HeaderText="Username">
                    <edititemtemplate>
                    <asp:TextBox ID="lbleditusr" runat="server" Text='<%#Eval("username") %>'/>
                    </edititemtemplate>
                    <itemtemplate>
                    <asp:Label ID="lblitemUsr" runat="server" Text='<%#Eval("username") %>'/>
                    </itemtemplate>
                    <footertemplate>
                    <asp:TextBox ID="txtftrusrname" runat="server"/>
                    <asp:RequiredFieldValidator ID="rfvusername" runat="server" ControlToValidate="txtftrusrname" Text="*" ValidationGroup="validaiton"/>
                    </footertemplate>


                    <asp:TemplateField  HeaderText="Password">
                         <edititemtemplate>
                             <asp:TextBox ID="txtpass" runat="server" Text='<%#Eval("password") %>'/>
                         </edititemtemplate>
                         <itemtemplate>
                             <asp:Label ID="lblpass" runat="server" Text='<%#Eval("password") %>'/>
                         </itemtemplate>
                         <footertemplate>
                          <asp:TextBox ID="txtftrpass" runat="server"/>
                          <asp:RequiredFieldValidator ID="rfvcity" runat="server" ControlToValidate="txtftrpass" Text="*" ValidationGroup="validaiton"/>
                         </footertemplate>

                    <asp:TemplateField HeaderText="Mail">
                         <edititemtemplate>
                             <asp:TextBox ID="txtmail" runat="server" Text='<%#Eval("mail") %>'/>
                         </edititemtemplate>
                         <itemtemplate>
                             <asp:Label ID="lblmail" runat="server" Text='<%#Eval("mail") %>'/>
                         </itemtemplate>
                         <footertemplate>
                             <asp:TextBox ID="txtftrmail" runat="server"/>
                        <asp:RequiredFieldValidator ID="rfvdesignation" runat="server" ControlToValidate="txtftrmail" Text="*" ValidationGroup="validaiton"/>
                         </footertemplate>

                    <asp:TemplateField>
                    <edititemtemplate>
                    <asp:ImageButton ID="imgbtnUpdate" CommandName="Update" runat="server" ImageUrl="~/gridviewimage/update.jpg" ToolTip="Update" Height="20px" Width="20px" />
                    <asp:ImageButton ID="imgbtnCancel" runat="server" CommandName="Cancel" ImageUrl="~/gridviewimage/Cancel.jpg" ToolTip="Cancel" Height="20px" Width="20px" />
                    </edititemtemplate>
                    <itemtemplate>
                    <asp:ImageButton ID="imgbtnEdit" CommandName="Edit" runat="server" ImageUrl="~/gridviewimage/Edit.jpg" ToolTip="Edit" Height="20px" Width="20px" />
                    <asp:ImageButton ID="imgbtnDelete" CommandName="Delete" Text="Edit" runat="server" ImageUrl="~/gridviewimage/delete.jpg" ToolTip="Delete" Height="20px" Width="20px" />
                    </itemtemplate>
                    <footertemplate>
                    <asp:ImageButton ID="imgbtnAdd" runat="server" ImageUrl="~/gridviewimage/AddNewitem.jpg" CommandName="AddNew" Width="30px" Height="30px" ToolTip="Add new User" ValidationGroup="validaiton" />
                    </footertemplate>

            </columns>
            <footerstyle backcolor="White" forecolor="#000066" />
            <HeaderStyle BackColor="#006699" Font-Bold="True" ForeColor="White" />
            <pagerstyle backcolor="White" forecolor="#000066" horizontalalign="Left" />
            <rowstyle forecolor="#000066" />
            <SelectedRowStyle BackColor="#669999" Font-Bold="True" ForeColor="White" />
            <sortedascendingcellstyle backcolor="#F1F1F1" />
            <sortedascendingheaderstyle backcolor="#007DBB" />
            <sorteddescendingcellstyle backcolor="#CAC9C9" />
            <sorteddescendingheaderstyle backcolor="#00547E" />











C#






C#

protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
   {
       GridView1.EditIndex = e.NewEditIndex;
       FillGrid();
   }
   protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
   {
       int id = Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Value.ToString());

       TextBox lbleditusr = (TextBox)GridView1.Rows[e.RowIndex].FindControl("lbleditusr");
       TextBox txtpass = (TextBox)GridView1.Rows[e.RowIndex].FindControl("txtpass");
       TextBox txtmail = (TextBox)GridView1.Rows[e.RowIndex].FindControl("txtmail");

       cmd = new SqlCommand("update getezee set username=@username,password=@password,mail=@mail where id=@id", con);
       cmd.Parameters.AddWithValue("@username", lbleditusr.Text);
       cmd.Parameters.AddWithValue("@password", txtpass.Text);
       cmd.Parameters.AddWithValue("@mail", txtmail.Text);
       cmd.Parameters.AddWithValue("@id", id);
       con.Open();
       cmd.ExecuteNonQuery();
       con.Close();
       FillGrid();

   }

推荐答案

cmd.Parameters.AddWithValue("@username", lbleditusr.Text);





在这种情况下lbledituser .Text不应该评估为null。



in this case lbledituser.Text should not evaluate to null.


这篇关于必须声明标量变量“@ username”。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-27 19:36