-- Open SQL Server 2005 and create database (PollDS) has table Employess which has fields EmployeeID (int , Primary Key , Identity) , FirstName (nvarchar , 50) , LastName(nvarchar , 50) , Salary (money), HireDate (datetime) , Phone (nvarchar , 15 , allow null) , City (nvarchar , 50) , Address (nvarchar , 50) , Email (nvarchar , 50)
-- create new web application and add wizard control from Toolbox
-- In Wizard control we will have three steps first step (Name) and add two lable (FirstName ,LastName) and two textbox (txtfirstname,txtlastname) and second step (Salary & HireDate) and add lable (Salary) and textbox (txtsalary) and calender and third step (More Information) and add four lable (Phone,Street,City,Email) and four textbox (txtphone,txtstreet,txtcity,txtemail)
** Default.aspx.cs
using System;
using System.Data;
using System.Configuration;using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
public void insertDataIntoDB( )
{
string connectionstring = "database=PollDB;data source=.;integrated security=true";
SqlConnection connection = new SqlConnection(connectionstring);
string query = "insert into Employees (FirstName,LastName,Salary,HireDate,Phone,Street,City,Email) values (@FirstName,@LastName,@Salary,@HireDate,@Phone,@Street,@City,@Email)"; SqlCommand command = new SqlCommand(query, connection);
command.Parameters.Add("@FirstName", SqlDbType.NVarChar, 50).Value = txtfirstname.Text;
command.Parameters.Add("@LastName", SqlDbType.NVarChar, 50).Value = txtlastname.Text;
command.Parameters.Add("@Salary",SqlDbType.Money).Value=txtsalary.Text.ToStrin(); command.Parameters.Add("@HireDate",SqlDbType.DateTime).Value=Calendar1.SelectedDate.ToShortDateString(); command.Parameters.Add("@Phone",SqlDbType.NVarChar,15).Value= txtphone.Text.ToString();
command.Parameters.Add("@Street", SqlDbType.NVarChar, 50).Value = txtstreet.Text; command.Parameters.Add("@City", SqlDbType.NVarChar, 50).Value = txtcity.Text; command.Parameters.Add("@Email", SqlDbType.NVarChar, 50).Value = txtemail.Text;
connection.Open();
command.ExecuteNonQuery();
connection.Close();
}
protected void Wizard1_FinishButtonClick(object sender, WizardNavigationEventArgs e)
{
insertDataIntoDB();
}
}
Wednesday, January 9, 2008
Subscribe to:
Post Comments (Atom)


No comments:
Post a Comment