我在面板中有表单,我使用表单中的存储过程将数据插入数据库。它不会抛出任何错误,但它不会在数据库中显示数据。代码成功运行,但表中的列为空。
这是我的存储过程:
CREATE procedure [dbo].[spDREG]
(@pname varchar(250),
@spname varchar(250),
@age int,
@spage int,
@cat varchar(50),
@mno bigint,
@emlid varchar(250),
@years varchar(50)
)
AS
BEGIN
DECLARE @dregid INT = @@identity
INSERT INTO DREG(P_NAME, SECP_NAME, AGE, AGET, CAT, MOB_NO, EMAILD, YEARS)
VALUES(@pname, @spname, @age, @spage, @cat, @mno, @emlid, @years)
END
这是我背后的代码
protected void Dsbtn_click(object sender, EventArgs e)
{
string psname ="spDREG"; ;
con.Open();
SqlCommand cmd = new SqlCommand(psname,con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@pname", TextBox1.Text.ToString());
cmd.Parameters.AddWithValue("@spname", TextBox2.Text.ToString());
cmd.Parameters.AddWithValue("@age", TextBox22.Text.ToString());
cmd.Parameters.AddWithValue("@spage", TextBox24.Text.ToString());
cmd.Parameters.AddWithValue("@cat", DropDownList1.Text.ToString());
cmd.Parameters.AddWithValue("@mno", TextBox4.Text.ToString());
cmd.Parameters.AddWithValue("@emlid", TextBox5.Text.ToString());
cmd.Parameters.AddWithValue("@years", DropDownList2.Text.ToString());
cmd.ExecuteNonQuery();
con.Close();
dreglbl.Text = "You have successfully registered";
}
这是我的设计部分
<asp:Panel runat="server" ID="dan" class="npan" Width="900px" Height="500px">
<h3 style="text-align: center" class="panhed">Please Fill This Form TO Participate(Dance Registration)</h3>
<div id="snam" runat="server" class="nam">
<asp:Label ID="Label2" runat="server" Text="Name of participant:"></asp:Label>
<asp:TextBox ID="TextBox1" CssClass="txtcls" runat="server" TextMode="MultiLine"></asp:TextBox>
<asp:Button ID="addm" class="addbtn" runat="server" autopostback="true" Text="Add member" OnClick="addm_Click" />
</div>
<div id="Div3" runat="server" class="nams">
<asp:Label ID="Label3" runat="server" autopostback="true" Text="Name of 2nd participant:"></asp:Label>
<asp:TextBox ID="TextBox2" CssClass="txtscls" runat="server"></asp:TextBox>
</div>
<div id="Div29" runat="server" class="nams">
<asp:Label ID="Label27" runat="server" Text="Age:"></asp:Label>
<asp:TextBox ID="TextBox22" CssClass="agtxt" placeholder="1st" runat="server"></asp:TextBox>
<asp:TextBox ID="TextBox24" CssClass="agstxt" placeholder="2nd" AutoPostBack="true" runat="server"></asp:TextBox>
</div>
<div id="Div2" runat="server" class="cate">
<asp:Label ID="Label4" runat="server" Text="Select Category:"></asp:Label>
<asp:DropDownList runat="server" ID="DropDownList1" Class="drpd" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
<asp:ListItem Value="22">select</asp:ListItem>
<asp:ListItem Value="Ss">Solo</asp:ListItem>
<asp:ListItem Value="Dd">Duet</asp:ListItem>
<asp:ListItem Value="Gg">Group</asp:ListItem>
</asp:DropDownList>
</div>
<div id="divv" class="mobn" runat="server">
<asp:Label ID="Label5" runat="server" Text="Mobile No:"></asp:Label>
<asp:TextBox ID="TextBox4" CssClass="mobtxt" runat="server"></asp:TextBox>
</div>
<div id="Div6" runat="server" class="eml">
<asp:Label ID="Label6" runat="server" Text="E-Mail:"></asp:Label>
<asp:TextBox ID="TextBox5" CssClass="emtxt" runat="server"></asp:TextBox>
</div>
<div id="Div7" runat="server" class="yer">
<asp:Label ID="Label7" runat="server" Text="Select Year:"></asp:Label>
<asp:DropDownList runat="server" ID="DropDownList2" Class="drpds">
<asp:ListItem>select</asp:ListItem>
<asp:ListItem>First</asp:ListItem>
<asp:ListItem>Second</asp:ListItem>
<asp:ListItem>Third</asp:ListItem>
<asp:ListItem>other</asp:ListItem>
</asp:DropDownList>
</div>
<div id="Div8" runat="server" class="btndiv">
<asp:Button ID="Dsbtn" runat="server" Class="Btncss" Text="Submit" OnClick="Dsbtn_click" />
<asp:Label ID="dreglbl" runat="server" Text="label"></asp:Label>
</div>
</asp:Panel>
请解决它们。谢谢