Jaya Prakash

Jaya Prakash

  • 543
  • 2.3k
  • 65.3k

Binding Image from db to gridview

Mar 1 2023 5:53 AM

when i click on register button i am getting all values but when i upload pic it is showing null value  help me out sir 

if (TextBox2.Text == "")
            {
                Response.Write("<script> alert('*please Enrter UserName') </script>");
                return;
            }
            else if (TextBox3.Text == "")
            {
                Response.Write("<script> alert('*please Enrter Password') </script>");
                return;
            }
            else if (TextBox4.Text == "")
            {
                Response.Write("<script> alert('*please Enrter valid  Email') </script>");
                return;
            }
           
            string Gender = "";
            if (RadioButton1.Checked == true)
            {
                Gender = RadioButton1.Text;
            }
            else
            {
                Gender = RadioButton2.Text;
            }
            string country = Convert.ToString(DropDownList1.SelectedItem);
            string state = Convert.ToString(DropDownList2.SelectedItem);
            string cit = Convert.ToString(DropDownList3.SelectedItem);
            
            if (Button1.Text == "Register")
            {
                if (FileUpload1.HasFile && FileUpload2.HasFile)
                {
                    string profileImageName = FileUpload1.PostedFile.FileName;
                    string profileImage = FileUpload2.PostedFile.FileName;
                    string filePath = Server.MapPath(@"~/Images/" + profileImageName);
                    string newfilepath = Server.MapPath(@"~/Images/" + profileImage);
                    FileUpload1.SaveAs(filePath);
                    FileUpload2.SaveAs(newfilepath);
                    string commandText = "insert into masterwithimg values ('" + TextBox2.Text + "','" + TextBox3.Text + "','" + TextBox4.Text + "','" + Convert.ToInt64(TextBox5.Text) + "','" + Gender + "','" + country + "','" + state + "','" + cit + "','~/Images/" + profileImageName + "','~/Images/" + profileImage + "')";
                    var com = new SqlCommand(commandText, Con);
                    Con.Open();
                    int result = com.ExecuteNonQuery();
                    if (result > 0)
                    {
                        BindEmployeeData();
                    }
                    else
                    {
                        Response.Write("nothing");
                    }
                    Con.Close();
                }

 


Answers (3)