i hope this code helps a bit
Excel.Application ep = new Excel.Application();
Excel.Workbook ewb = ep.Workbooks.Open(openFileDialog1.FileName);
Excel.Worksheet ews = ewb.Sheets[1];
Excel.Range range = ews.UsedRange;
int rowCount = range.Rows.Count;
int columnCount = range.Columns.Count;
for (int i = 1; i <= rowCount; i++)
{
set_id();
id = cmb_id.Text;
int n = 0;
for (int j = 1; j <= columnCount; j++)
{
n = n + 1;
string str = Convert.ToString((range.Cells[i, j] as Excel.Range).Value2);
if (n == 2)
{
photo =txt_img_loc.Text + str + ".jpg";
try
{
pbx_photo.Image = Image.FromFile(photo);
}
catch { MessageBox.Show("Inalid path or image"); }
}
else if (n == 1)
{
seat_no = str;
}
.................
else if (n == 21)
{
try
{
time = str;
}
catch
{
}
}
}
try
{
pbx_photo.Image.Save(Application.StartupPath + "\\Image\\" + cmb_id.Text + ".jpg");
}
catch
{
pbx_photo.Image = Image.FromFile(Application.StartupPath + "\\Default\\User-icon.png");
pbx_photo.Image.Save(Application.StartupPath + "\\Image\\" + cmb_id.Text + ".jpg");
}
try
{
qry = "insert into entry(ety_id,ety_seat_no,ety_name,ety_house_name,ety_father_guar,ety_age,ety_gender,ety_qualification,ety_blood_group," +
"ety_panchayath,ety_ward_unit,ety_location,ety_designation,ety_occupation,ety_office,ety_land_line,ety_mobile,ety_email," +
"ety_photo,ety_date) values('" + id + "','"+ seat_no +"','" + name + "','" + house + "'," +
"'" + father + "','" + age + "','" + sex + "','" + quali + "'," +
"'" + blood + "','" + panch + "','" + ward + "','" + loca + "'," +
"'" + design + "','" + occ + "','"+ office +"','" + land + "','" + mob + "'," +
"'" + email + "','" + photo + "','" + str1 + "')";
sql_cmd = new SqlCommand(qry, sql_con);
sql_con.Open();
sql_cmd.ExecuteNonQuery();
sql_con.Close();
add_id();
set_id();
pbx_photo.Image = null;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}