.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Forum >> ASP.Net >> Post New QuestionBookmark and Share Subscribe to Forum

i got a problem on registration form using stored procedure and classes

Posted By: raj     Posted Date: December 02, 2009    Points:2   Category :ASP.Net
//this is class file

public void insertreg(string firstname, string lastname, Int32 phonenumber, string email, string street, string state, string city, Int32 zipcode, string username, string password, string confirmpassword, DateTime DOB, string gender, string martialstatus)
{
SqlConnection con = new SqlConnection(" server=home;uid=sa;password=SWATHI;database=R");
SqlCommand cmd = new SqlCommand(spreg1, con);
cmd.CommandType = CommandType.StoredProcedure;

SqlParameter pfirstname = new SqlParameter();
pfirstname.ParameterName = "@Firstname";
pfirstname.value = firstname;
pfirstname.SqlDbType = SqlDbType.VarChar;
pfirstname.Size = 20;
cmd.Parameters.Add(pfirstname);

SqlParameter plastname = new SqlParameter();
plastname.ParameterName = "@Lastname";
plastname.Value = lastname;
plastname.SqlDbType = SqlDbType.VarChar;
plastname.Size = 20;
cmd.Parameters.Add(plastname);

SqlParameter ppnumber = new SqlParameter();
ppnumber.ParameterName = "@phonenumber";
ppnumber.Value = phonenumber;
ppnumber.SqlDbType = SqlDbType.Int;
ppnumber.Size = 4;
cmd.Parameters.Add(ppnumber);

SqlParameter pemail = new SqlParameter();
pemail.parameterName = "@Email";
pemail.Value = email;
pemail.SqlDbType = SqlDbType.VarChar;
pemail.Size = 20;
cmd.Parameters.Add(pemail);

SqlParameter pstreet= new SqlParameter();
pstreet.parameterName = "@Street";
pstreet.Value = street;
pstreet.SqlDbType = SqlDbType.VarChar;
pstreet.Size = 30;
cmd.Parameters.Add(pstreet);

SqlParameter pstate = new SqlParameter();
pstate.parameterName = "@State";
pstate.Value = state;
pstate.SqlDbType = SqlDbType.VarChar;
pstate.Size = 20;
cmd.Parameters.Add(pstate);

SqlParameter pcity = new SqlParameter();
pcity.parameterName = "@City";
pcity.Value = city;
pcity.SqlDbType = SqlDbType.VarChar;
pcity.Size = 20;
cmd.Parameters.Add(pcity);

SqlParameter pzcode = new SqlParameter();
pzcode.parameterName = "@Zipcode";
pzcode.Value = zipcode;
pzcode.SqlDbType = SqlDbType.VarChar;
pzcode.Size = 20;
cmd.Parameters.Add(pzcode);

SqlParameter puname = new SqlParameter();
puname.parameterName = "@Username";
puname.Value = username;
puname.SqlDbType = SqlDbType.VarChar;
puname.Size = 20;
cmd.Parameters.Add(puname);

SqlParameter ppwd = new SqlParameter();
ppwd.parameterName = "@password";
ppwd.Value = password;
ppwd.SqlDbType = SqlDbType.VarChar;
ppwd.Size = 20;
cmd.Parameters.Add(ppwd);

SqlParameter pcpwd = new SqlParameter();
pcpwd.parameterName = "@confirmpassword";
pcpwd.Value = confirmpassword;
pcpwd.SqlDbType = SqlDbType.VarChar;
pcpwd.Size = 20;
cmd.Parameters.Add(pcpwd);

SqlParameter pdob = new SqlParameter();
pdob.ParameterName = "@DOB";
pdob.Value = DOB;
pdob.SqlDbType = SqlDbType.DateTime;
pdob.Size = 8;
cmd.Parameters.Add(pdob);

SqlParameter pgen = new SqlParameter();
pgen.ParameterName = "@Gender";
pgen.Value = gender;
pgen.SqlDbType = SqlDbType.VarChar;
pgen.Size = 10;
cmd.Parameters.Add(pgen);

SqlParameter pmstatus = new SqlParameter();
pmstatus.ParameterName = "@Martialstatus";
pmstatus.Value = martialstatus;
pmstatus.SqlDbType = SqlDbType.VarChar;
pmstatus.Size = 10;
cmd.Parameters.Add(pmstatus);



con.Open();
cmd.ExecuteNonQuery();
con.Close();
}

//code for buttonclick

protected void btnsub_Click(object sender, EventArgs e)
{
register rg = new register();
rg.insertreg(txtFName.Text,txtlname.Text,txtphone.Text,txtemail.Text,txtstreet.Text,dstate.Text,dcity.Text,int.Parse(txtzcode.Text),txtuname.Text,txtpwd.Text,txtcpwd.Text,int.Parse(txtdob.Text),rbtgender.Text,rbtmstatus.Text)

}

//code for default.aspx

<form id="form1" runat="server" >&nbsp;&nbsp;&nbsp;&nbsp;
<table id="tblRegister" border="1" cellpadding="0" cellspacing="0"
align="center" bgcolor="#FF99CC">
<tr>
<td style="WIDTH: 128px">First Name:</td>
<td><asp:textbox id="txtFName" runat="server"></asp:textbox></td>
</tr>
<tr>
<td align="left"> Last Name:</td>
<td><asp:TextBox ID="txtlname" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td>MartialStatus:</td>
<td><asp:RadioButtonList ID="rbtmstatus" runat="server" RepeatDirection="Horizontal">
<asp:ListItem Value="married">Married</asp:ListItem>
<asp:ListItem Value="Unmarried">Unmarried</asp:ListItem>
</asp:RadioButtonList></td>
</tr>
<tr>
<td>Gender:</td>
<td><asp:RadioButtonList ID="rbtgender" runat="server" RepeatDirection="Horizontal">
<asp:ListItem Value="male">male</asp:ListItem>
<asp:ListItem Value="female">Female</asp:ListItem>
</asp:RadioButtonList></td>

</tr>
<tr>
<td>DOB:</td>
<td><asp:TextBox ID="txtdob" runat="server"></asp:TextBox></td>

</tr>
<tr>
<td>Phone number:</td>
<td><asp:TextBox ID="txtphone" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td>Email:</td>
<td><asp:TextBox ID="txtemail" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td>Street:</td>
<td><asp:TextBox ID="txtstreet" runat="server" TextMode="MultiLine"></asp:TextBox></td>
</tr>
<tr>
<td>State:</td>
<td><asp:DropDownList ID="dstate" runat="server">
<asp:ListItem>---select state----</asp:ListItem>
<asp:ListItem>AP</asp:ListItem>
<asp:ListItem>MP</asp:ListItem>
<asp:ListItem>UP</asp:ListItem>
<asp:ListItem>Chennai</asp:ListItem>
</asp:DropDownList></td>
</tr>
<tr>
<td>City:</td>
<td><asp:DropDownList ID="dcity" runat="server" ForeColor="#FF6699">
<asp:ListItem>Hyd</asp:ListItem>
<asp:ListItem>vizag</asp:ListItem>
<asp:ListItem>vijaywada</asp:ListItem>

</asp:DropDownList></td>

</tr>
<tr>
<td>zipcode:</td>
<td><asp:TextBox ID="txtzcode" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td>Username:</td>
<td><asp:TextBox ID="txtuname" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td>Password:</td>
<td><asp:TextBox ID="txtpwd" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td>Confirm password:</td>
<td><asp:TextBox ID="txtcpwd" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td><asp:CheckBox ID="chk1" runat="server" Text="I have accept the terms and conditions" /></td>
<td align="center"><asp:Button ID="btnsub" runat="server" Text="submit"
onclick="btnsub_Click" /></td>
</tr>


</table>


</form>

Responses
Author: Amit Mehra             
Posted Date: December 02, 2009     Points: 5   

Hello Raj,

What error you are getting? If you could tell us it would better to understand the problem.

Thanks
Amit

Thanks,
Amit
Please "Mark As Answer " if this post help you.


Post Reply

You must Sign In To post reply
 
 
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery
JavaScript/VBScriptBiztalkWPFPatten/PracticesWCFOthers
www.DotNetSpark.comUnAnsweredAll

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend