Friday, February 24, 2012

c# signup form into sql database

Hi all,I'm trying to do an extremely simple task here: add information from a signup form into an SQL database. Sadly, I can't figure out how to get the values into the DB.Here's my form:


<form id="form1" runat="server">
<div>
<asp:Label ID="lblName" runat="server" Text="Your Name:"></asp:Label>
<br />
<asp:TextBox ID="txtName" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="txtName"
ErrorMessage="RequiredFieldValidator"></asp:RequiredFieldValidator><br />
<asp:Label ID="lblEmail" runat="server" Text="Your Email Address:"></asp:Label>
<br />
<asp:TextBox ID="txtEmail" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="txtEmail"
ErrorMessage="RequiredFieldValidator"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="txtEmail"
ErrorMessage="RegularExpressionValidator" ValidationExpression="\w+([-+.']\w+)*@.\w+([-.]\w+)*\.\w+([-.]\w+)*"></asp:RegularExpressionValidator><br />
<br />
<asp:Label ID="lblSubscribe" runat="server" AssociatedControlID="radSubscribe" Text="Subscribe"></asp:Label>
<asp:RadioButton ID="radSubscribe" runat="server" Checked="True" /><br />
<br />
<asp:Label ID="lblUnsubscribe" runat="server" AssociatedControlID="radUnsubscribe"
Text="Unsubscribe"></asp:Label>
<asp:RadioButton ID="radUnsubscribe" runat="server" /><br />
<br />
<asp:Button ID="btnSignup" runat="server" Text="Signup" OnClick="btnSignup_Click" /></div>
</form>

And here's my Stored procedure I've written:

create procedure sp_customerSignups

@.name varchar(50),
@.email varchar (50),
@.subscribed int

as

BEGIN

INSERT INTO tblCustomerSignups(Name, EmailAddress, Subscribed)

VALUES(@.name, @.email, @.subscribed)

END

How do I get the values from the form into the DB and forward them to a 'successful' message. Also if the user clicks the radSubscribe button I want the field in SQL to be 1 and if the user clicks radUnsubscribe the field to be 0.I'm trying to do this in C# and I feel as if my brain is about to burst with all I've learnt over the past weeks!Thanks in advance,Brett

Solved.

No comments:

Post a Comment