protected void Button1_Click(object sender, EventArgs e)
{
if (!FileUpload1.HasFile)
{
Label3.Visible = true;
Label3.Text = "Please Select Image File"; //checking if file uploader has no file selected
}
else
{
FileUpload1.SaveAs(Server.MapPath(Request.ApplicationPath + "//Picture//" //foldername
+ FileUpload1.FileName));
this.Session["Path"] = "~//Picture//" + this.FileUpload1.FileName;
//string path= "~/Picture/" ;
//int length = FileUpload1.PostedFile.ContentLength;
//byte[] pic = new byte[length];
//FileUpload1.PostedFile.InputStream.Read(pic, 0, length);
try
{
cn.Open(); //calling connection method//inserting uploaded image query
SqlCommand cmd = new SqlCommand("insert into tblStudent "
+ "(std_ID,std_Name,std_Password,std_ContactNumber,std_Address,std_Image,module_ID,intake_Code) values (@std_ID,@std_Name,@std_Password,@std_ContactNumber,@std_Address,@std_Image,@module_ID,@intake_Code)", cn);
cmd.Parameters.AddWithValue("@std_ID", TextBox2.Text);
cmd.Parameters.AddWithValue("@std_Name", TextBox1.Text);
cmd.Parameters.AddWithValue("@std_Password", TextBox3.Text);
cmd.Parameters.AddWithValue("@std_ContactNumber", TextBox4.Text);
cmd.Parameters.AddWithValue("@std_Address", TextBox5.Text);
cmd.Parameters.AddWithValue("@std_Image",FileUpload1.FileName );
string checkboxlist;
for (int i = 0; i < CheckBoxList1.Items.Count; i++) {
if (CheckBoxList1.Items[i].Selected) {
checkboxlist = string.Empty;
checkboxlist = CheckBoxList1.Items[i].Text.ToString();
}
}
string module_id = "";
if (CheckBoxList1.Items[0].Selected == true) {
module_id = CheckBoxList1.Items[0].Value;
}
if (CheckBoxList1.Items[1].Selected == true) {
if (module_id == "")
{
module_id = CheckBoxList1.Items[1].Value;
}
else {
module_id = module_id + "%" + CheckBoxList1.Items[1].Value;
}
}
if (CheckBoxList1.Items[2].Selected == true)
{
if (module_id == "")
{
module_id = CheckBoxList1.Items[2].Value;
}
else
{
module_id = module_id + "%" + CheckBoxList1.Items[2].Value;
}
}
string[] words = module_id.Split('%');
cmd.Parameters.AddWithValue("@module_ID", module_id);
cmd.Parameters.AddWithValue("@intake_Code", DropDownList1.SelectedValue);
cmd.ExecuteNonQuery();
System.Windows.Forms.MessageBox.Show("New Account Register Successfully!");
Response.Redirect("AdminHome.aspx", true);
}
finally
{
cn.Close();
}
}
}