Hello i'm new to asp.net and i'm doing this project for my academics. please help
P.S: currently i'm getting an error and it is
"you must provide an initializer in a fixed or using statement declaration"
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 Button2_Click(object sender, EventArgs e)
{
Response.Redirect("home.aspx");
}
protected void Button1_Click(object sender, EventArgs e)
{
using (SqlCommand cnd = new SqlCommand("select LAST EmpID from Emplo"),con)
{
}
using (SqlCommand cmd = new SqlCommand("Insert into Emplo ([Name],[Password],[Designation],[Dept],[D O B],[Sex],[Address]) values (@Name,@pass,@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;
string sa = CreateRandomPassword(6);
cmd.Parameters.Add("@pass", SqlDbType.VarChar).Value = sa;
con.Open();
cmd.ExecuteNonQuery();
Response.Write("<script>alert('Registered successfully......!')</script>");
Response.Write("<script>alert('Password is " + Server.HtmlEncode(sa.ToString()) + "')</script>");
}
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);
}
}