private void button1_Click_1(object sender, EventArgs e)
{
try
{
string fname = txtfname.Text;
string lname = txtlname.Text;
string house = txthouse.Text;
string city = txtcity.Text;
string country = txtcountry.Text;
string state = txtstate.Text;
string post = txtpost.Text;
string mail = txtmail.Text;
string blood = txtblood.Text;
string mobile = txtmobile.Text;
string dob = txtdob.Text;
if (label24.Text != "file path")
{
byte[] imagedata = ReadFile(label24.Text);
string conn = "Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|NORTHWND.MDF;Integrated Security=True;User Instance=True";
SqlConnection con = new SqlConnection(conn);
string query = "insert into address(firstname,lastname,house,city,country,state,post,mail,blood,mobile,dob,image)values
('" + fname + "','" + lname + "','" + house + "','" + city + "','" + country + "','" + state + "','" + post + "','" + mail + "','" + blood + "','" + mobile + "','" + dob + "',@image)";
SqlCommand cmd = new SqlCommand(query, con);
cmd.Parameters.Add(new SqlParameter("@image", (object)imagedata));
con.Open();
cmd.ExecuteNonQuery();
con.Close();
rInsert.Text = "Address Saved Sucessfully...!!!";
}
else
MessageBox.Show("Please Insert a Photo", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
catch (Exception x)
{
MessageBox.Show(x.ToString());
}
}
byte[] ReadFile(string sPath)
{
byte[] data = null;
FileInfo fInfo = new FileInfo(sPath);
long numBytes = fInfo.Length;
FileStream fStream = new FileStream(sPath, FileMode.Open, FileAccess.Read);
BinaryReader br = new BinaryReader(fStream);
data = br.ReadBytes((int)numBytes);
return data;
}