HOME AJAX VALIDATION EMAIL ADO.NET SILVERLIGHT CONTACT US |
Here are going to change the username of the user simply identifying him by his email.
Create a New website. >> select an Empty website. click OK.
Now, First thing we want to do is design a GUI that can enter the data into the database table. (assuming that the database table is already created).
Go to the default.aspx designer and insert following things:
- "2 textboxes and labels each for email, New username. respectively."
- 1 asp button to submit the data.
- and 1 label
Here is the design exaple:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
Email
<asp:TextBox ID="TextBox1" runat="server" BackColor="#999966" Height="32px"
Width="245px"></asp:TextBox>
<br />
New Username
<asp:TextBox ID="TextBox3" runat="server" BackColor="#999966" Height="32px"
Width="245px"></asp:TextBox>
<br />
<br />
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Submit" />
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<br />
</div>
</form>
</body>
</html>
After Doing all the above things your design page may look some what like this.
Now , After GUI, next step is the code behind the page.
Goto the Defsult .aspx.cs page .
First add the Namespace to this page which is very important to use sql elements.
add> System.Data.SqlClient in the namespaces at the top of page.
Go to the graphics designer page and double click the submit button. The click event of button will be shown. Inside it write the following code.
for example-
{
string s = "<CONNECTION STRING OF UR DATABASE>";
SqlConnection c = new SqlConnection(s);
try
{
SqlCommand cmd = new SqlCommand(" UPDATE INTO <TABLE NAME> (Password) VALUES ('"+TextBox3.Text+"' ) where email= '"+TextBox1.Text+"' " ,c );
// above coloumn names should be changed to your database table's coloumn names.
c.Open();
cmd.ExecuteNonQuery();
Label1.Text = "Data Updated Successfully";
}
catch(Ex)
{
Console.WriteLine(Ex.Message);
}
finally
{
c.Close();
}
}
Note: Please be careful about data types of the coloumn (password coloumn) while making the table. also coloumn names and table name should be matching to your database.
If all the things are followed correctly then you must be able to insert the data into database. Refresh your database and see in your database whether the data has been inserted correctly or not.
Please feel free to comment as it helps and motivates me to write the blog.
Thank you!!
-Vaibhav Patil.
HOME AJAX VALIDATION EMAIL ADO.NET SILVERLIGHT CONTACT US
No comments:
Post a Comment