Login Application in (aspx) asp.net
Creating the Data Base:
step 1: First open the Microsoft SQL server 2008.
step 2: Then Connecting the SQL server and Open the New Query sheet and type the follwoing:
create database test // select whole line and press F5.
step 3: Then Creating the table for appropriate DataBase. To Create the table type following query::
create table registration (username varchar(50), pwd varchar(30), repwd varchar(30), gender varchar(30) , qual varchar(30) , addr varchar(30) , mobno varchar(10), country varchar(30) ) ;
// select whole line and press F5.
step 4: Now u will see the output in Table format.
Creating the Registration Form in ASP.NET using C#:
step 1: Open the Microsoft Visual Studio 2008 and select New Web Site with Language::: c#.
step 2: Double Click in the Empty Space in Registration Form Then type the following::
<head> </head>
<body>
<div>
<table cellspacing=0 cellpadding=0 >
<tr>
<td>
<asp:Label runat="server" Text="UserName"/>
</td>
<td>
<asp:TextBox runat="server" Text="" Name="tbus"/>
</td>
</tr>
<tr>
<td>
<asp:Label runat="server" Text="Password"/>
</td>
<td>
<asp:TextBox runat="server" Text="" Name="tbpwd" TextMode="password"/>
</td>
</tr>
<tr>
<td>
<asp:Label runat="server" Text="Confirm Password"/>
</td>
<td>
<asp:TextBox runat="server" Text="" Name="tbrepwd" TextMode="password"/>
</td>
</tr>
<tr>
<td>
<asp:Label runat="server" Text="Password"/>
</td>
<td>
<asp:TextBox runat="server" Text="" Name="tbpwd" TextMode="password"/>
</td>
</tr>
<tr>
<td>
<asp:Label runat="server" Text="Gender"/>
</td>
<td>
<asp:RadioButton runat="server" GroupName="regrp" Text="Male" Name="rdmale" Checked="True"/>
<asp:RadioButton runat="server" GroupName="regrp" Text="Female" Name="rdfemale" Checked="True"/>
</td>
</tr>
<tr>
<td>
<asp:Label runat="server" Text="Qualification"/>
</td>
<td>
<asp:ListItem runat="server" Text="Select" value=-1 Name="ltqual">
<item text="MCA">
<item text="BE">
<item text="BTECH">
<item text="MBA">
</asp:ListItem>
<item text="MCA">
<item text="BE">
<item text="BTECH">
<item text="MBA">
</asp:ListItem>
</td>
</tr>
<td>
<asp:Button id="btnregister" runat="server" Text="Register" OnClick="btnregister_Click()"/>
<asp:Button id="btnupdate" runat="server" Text="Update"OnClick="btnupdate_Click()" />
<asp:Button id="btnclr" runat="server" Text="Clear" OnClick="btnclr_Click()" />
<asp:Button id="btnlog" runat="server" Text="GoToLogin"OnClick="btnlog_Click()" />
</td>
</tr>
<tr>
<td>
<asp:Label runat="server" Text="Address"/>
</td>
<td>
<asp:TextBox runat="server" Text="" Name="tbaddr" TextMode="MultiLine"/>
</td>
</tr>
<tr>
<tr>
<tr>
<td>
<asp:Label runat="server" Text="Mobile No"/>
</td>
<td>
<asp:TextBox runat="server" Text="" Name="tbmobno" />
</td>
</tr>
<tr>
<td>
<asp:Label runat="server" Text="Country"/>
</td>
<td>
<asp:CheckBox runat="server" Text="INDIA" Name="ckindia" />
<asp:CheckBox runat="server" Text="USA" Name="ckusa" />
<asp:CheckBox runat="server" Text="USA" Name="ckusa" />
</td>
</tr>
<td>
<asp:Button id="btnregister" runat="server" Text="Register" OnClick="btnregister_Click()"/>
<asp:Button id="btnupdate" runat="server" Text="Update"OnClick="btnupdate_Click()" />
<asp:Button id="btnclr" runat="server" Text="Clear" OnClick="btnclr_Click()" />
<asp:Button id="btnlog" runat="server" Text="GoToLogin"OnClick="btnlog_Click()" />
</td>
</tr>
</table>
</div>
</body>
GoTo Web.Config
1. Find out ConnectinStrings and type the following :
<ConnectionStrings>
<add name="dbconstr" ConnectionString=" server=mypc\SQLEXPRESS; DataBase=test; Integrated Security=TRUE "/>
</ConnectionStrings>
GoTo registration.aspx
step 1: Add following header in .aspx page:
Using System.Data.SqlClient;
and then type following code inside of the Namespace {........
private string GetConnectionString()
{
return System.Configuration.ConfigurationManager.ConnectionStrings["dbconstr"].Connectionstring;
}
private void btnregister_Click(object sender, EventArgs e)
{
String newgender="";
String newctry="";
if(rdfemale.Checked == TRUE)
newgender="Female";
else
newgender="Male";
if(ckindia.Checked == TRUE)
newctry="INDIA";
if(ckusa.Checked==TRUE)
newctry="USA";
SqlConnection con = new SqlConnection(GeConnectionString());
String sqlstmt = string.Empty;
sqlstmt = " insert into register values('"+ tbus.Text +"', '"+ tbpwd.Text +"', '"+ tbrepwd.Text +"', '"+ newgender +"', '"+ltqual.Text+"' , '"+ tbaddr.Text +"', '"+ tbmobno.Text +"', '"+ newctry +"') " ;
try
{
con.open();
sqlCommand cmd=new sqlCommand(sqlstmt, con);
int n=cmd.ExecuteNonQuery();
Response.write("Registration Successfully");
}
catch(sqlException ex)
{
string msg = "Registration Error";
msg += ex.Message();
throw new Exception(msg);
}
finally
{
con.close();
}
} // end of register button
private void btnupdate_Click(object sender, EventArgs e)
{
String newgender="";
String newctry="";
if(rdfemale.Checked == TRUE)
newgender="Female";
else
newgender="Male";
if(ckindia.Checked == TRUE)
newctry="INDIA";
if(ckusa.Checked==TRUE)
newctry="USA";
SqlConnection con = new SqlConnection(GeConnectionString());
String sqlstmt = string.Empty;
sqlstmt = " Update register set pwd='"+ tbpwd.Text +"', repwd= '"+tbrepwd.Text+"', gender= '"+newgender+"', qual= '"+ltqual.Text+"', addr= '"+tbaddr.Text+"', mobno= '"+tbmobno.Text+"' ,country= '"+newctry+"' where username= '"+tbus.Text+"' " ;
try
{
con.open();
sqlCommand cmd=new sqlCommand(sqlstmt, con);
int n=cmd.ExecuteNonQuery();
Response.write("Updated Successfully");
}
catch(sqlException ex)
{
string msg = "Updation Error";
msg += ex.Message();
throw new Exception(msg);
}
finally
{
con.close();
}
} // end of update button
private void btnclr_Click(object sender, EventArgs e)
{
tbus.Text="";
tbpwd.Text="";
tbrepwd.Text="";
rdfemale.Checked=False;
rdmale.Checked=TRUE;
ltqual.Selected=-1;
tbaddr.Text="";
tbmobno.Text="";
ckindia.Checked=False;
ckusa.Checked=False;
}
private void btnlog_Click(object sender, EventArgs e)
{
Response.Redirect("home.aspx");
}
This project is continuing.... please click LOGIN page in page menu
No comments:
Post a Comment