using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data.SqlClient; using System.Data; public partial class _Default : System.Web.UI.Page { SqlConnection con = new SqlConnection("Data Source=JIMMY-PC;initial Catalog=jimmy;Integrated Security=true"); protected void Page_Load(object sender, EventArgs e) { } protected void Button1_Click(object sender, EventArgs e) { using(SqlCommand cmd = new SqlCommand("Insert into Emplo ([Name],[Designation],[Dept],[D O B],[Sex],[Address]) values (@Name,@des,@dept,@DOB,@Sex,@Address)", con)) { cmd.Parameters.Add("@Name", SqlDbType.VarChar).Value = TextBox1.Text; cmd.Parameters.Add("@des", SqlDbType.VarChar).Value = TextBox2.Text; cmd.Parameters.Add("@dept", SqlDbType.VarChar).Value = TextBox3.Text; cmd.Parameters.Add("@DOB", SqlDbType.SmallDateTime).Value = TextBox4.Text; cmd.Parameters.Add("@Sex", SqlDbType.VarChar).Value = RadioButton1.SelectedItem.Text; cmd.Parameters.Add("@Address", SqlDbType.VarChar).Value = TextBox5.Text; con.Open(); cmd.ExecuteNonQuery(); Response.Write("<script>alert('Registered successfully......!')</script>"); } //string c=CreateRandomPassword(); using (SqlCommand cmd = new SqlCommand("insert into Emplo([Password]) values (@pass)", con)) { cmd.Parameters.Add("@pass", SqlDbType.VarChar).Value = CreateRandomPassword(6); cmd.ExecuteNonQuery(); } con.Close(); } public static string CreateRandomPassword(int PasswordLength) { string allowdChars = "0123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNOPQRSTUVWXYZ"; Random randNum = new Random(); char[] chars = new char[PasswordLength]; int allowedCharCount = allowdChars.Length; for (int j = 0; j < PasswordLength; j++) { chars[j] = allowdChars[(int)((allowdChars.Length) * randNum.NextDouble())]; } return new string(chars); } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)