本文介绍了必须在delete语句中声明标量变量“@UserId”。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
ASP.code
ASP.code
<%@ Page Title="" Language="C#" MasterPageFile="~/home.master" AutoEventWireup="true" CodeFile="register.aspx.cs" Inherits="register" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
<style type="text/css">
.auto-style15 {
width: 91px;
}
.auto-style16 {
width: 91px;
height: 23px;
}
.auto-style17 {
height: 23px;
border: 2px solid #a1a1a1;
border-radius:5px;
margin-top:50px;
margin-left:300px;
padding-left:0;
}
.auto-style18 {
width: 235px;
}
.auto-style19 {
width: 235px;
height: 23px;
}
.auto-style20 {
width: 91px;
height: 26px;
}
.auto-style21 {
width: 235px;
height: 26px;
}
.auto-style22 {
width: 91px;
height: 37px;
}
.auto-style23 {
width: 235px;
height: 37px;
margin-left: 40px;
}
.grid{
margin-left:150px;
margin-top:50px;
}
.activex{
margin-left:150px;
margin-top:30px;
}
</style>
<script type="text/javascript">
function Confirmationbox() {
var result = confirm('Are you sure you want to delete selected User(s)?');
if (result) {
return true;
}
else {
return false;
}
}
</script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<table class="auto-style17">
<tr>
<td class="auto-style15" align="center">username</td>
<td class="auto-style18" >
<asp:TextBox ID="TextBox2" runat="server" Width="171px"></asp:TextBox>
</td>
</tr>
<tr>
<td class="auto-style20" align="center">password</td>
<td class="auto-style21">
<asp:TextBox ID="TextBox3" runat="server" Width="171px" TextMode="Password"></asp:TextBox>
</td>
</tr>
<tr>
<td class="auto-style16" align="center">confirm mail</td>
<td class="auto-style19">
<asp:TextBox ID="TextBox4" runat="server" Width="171px"></asp:TextBox>
</td>
</tr>
<tr>
<td class="auto-style15" align="center">upload image</td>
<td class="auto-style18">
<asp:FileUpload ID="FileUpload1" runat="server"/>
</td>
</tr>
<tr>
<td class="auto-style15"> </td>
<td class="auto-style18"> </td>
</tr>
<tr>
<td class="auto-style22"></td>
<td class="auto-style23">
<asp:Button ID="Button1" runat="server" Text="Submit" Width="65px" OnClick="Button1_Click1" />
<asp:Button ID="Button2" runat="server" style="margin-left: 14px" Text="Reset" />
</td>
</tr>
<tr>
<td class="auto-style22"> </td>
<td class="auto-style23">
<asp:Label ID="Label9" runat="server" Text="Label"></asp:Label>
</td>
</tr>
</table>
<div class="activex">
<table><tr>
<td>
<asp:TextBox ID="TextBox1" runat="server" placeholder="Search id"></asp:TextBox>
<td>
<td>
<asp:Button ID="Button3" runat="server" Text="Delete" OnClientClick="javascript:validateCheckBoxes()" OnClick="Button3_Click"/>
</td>
</tr>
</table>
</div>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="userid" DataSourceID="SqlDataSource1" Width="608px" CssClass="grid" AllowPaging="True" AllowSorting="True" BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" CellPadding="3">
<Columns>
<asp:TemplateField>
<HeaderTemplate>
<asp:CheckBox ID="chkheader" runat="server" />
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="chkchild" runat="server"/>
</ItemTemplate>
<HeaderStyle HorizontalAlign="right" />
<ItemStyle HorizontalAlign="right" />
</asp:TemplateField>
<asp:BoundField DataField="userid" HeaderText="userid" InsertVisible="False" ReadOnly="True" SortExpression="userid" />
<asp:BoundField DataField="username" HeaderText="username" SortExpression="username" />
<asp:BoundField DataField="password" HeaderText="password" SortExpression="password" />
<asp:BoundField DataField="mail" HeaderText="mail" SortExpression="mail" />
<asp:BoundField DataField="imagename" HeaderText="imagename" SortExpression="imagename" />
<asp:ImageField DataImageUrlField="uploadimage" HeaderText="uploadimage">
<ControlStyle Width="100%" Height="100%"/>
</asp:ImageField>
</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" />
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:prakashConnectionString %>" SelectCommand="SELECT * FROM [getezeeregister] order by userid desc" DeleteCommand="delete from [getezeeregister] where userid= @userid">
<DeleteParameters>
<asp:Parameter Name="userid"/>
<asp:Parameter Name="username"/>
<asp:Parameter Name="password"/>
<asp:Parameter Name="mail"/>
<asp:Parameter Name="imagename"/>
<asp:Parameter Name="uploadimage"/>
</DeleteParameters>
</asp:SqlDataSource>
</asp:Content>
C# code
C# code
protected void Button3_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("Data Source=MAC-20;Initial Catalog=prakash;User ID=****;Password=*******");
con.Open();
cmd = new SqlCommand("delete from getezeeregister where userid=@userid",con);
cmd.ExecuteNonQuery();
con.Close();
}
推荐答案
C# code
C# code
protected void Button3_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("Data Source=MAC-20;Initial Catalog=prakash;User ID=****;Password=*******");
con.Open();
cmd = new SqlCommand("delete from getezeeregister where userid=@userid",con);
cmd.ExecuteNonQuery();
con.Close();
}
cmd.Parameters.AddWithValue("@userid", UserID);
这篇关于必须在delete语句中声明标量变量“@UserId”。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!