این کد دکمه brows
this.openFileDialog1.FileName = "*.xlsx"; if (this.openFileDialog1.ShowDialog() == DialogResult.OK)
{
this.Cursor = Cursors.WaitCursor;
OleDbConnection cn = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12. 0;Data Source=" + openFileDialog1.FileName.ToString() + ";Extended Properties=\"Excel 12.0;IMEX=1;HDR=NO;TypeGuessRows=0;ImportMixedType s=Text\"");
cn.Open();
OleDbCommand qstr = cn.CreateCommand();
qstr.CommandText = "select * from [sheet1$]";
OleDbDataAdapter ad = new OleDbDataAdapter(qstr);
ad.Fill(dt);
dataGridViewX1.DataSource = dt;
labelX1.Text = openFileDialog1.FileName;
this.Cursor = Cursors.Default;
}
dataGridViewX1.Columns[0].HeaderText = "شماره کوتاژ";
dataGridViewX1.Columns[1].HeaderText = "تاریخ تصویه";
}
این کد ذخیره کردن هست
{ string s,sd="",ss="";
this.Cursor = Cursors.WaitCursor;
cnd.getcn().Open();
for (int i = 0; i < dt.Rows.Count; i++)
{
for (int j = 0; j < (dt.Columns.Count) - 1; j++)
{
SqlCommand cm3 = new SqlCommand("insert into tblRefine (Ref_Nkootaj,Ref_date) values (@N,@D)", cnd.getcn());
cm3.Parameters.Add("@N", SqlDbType.Int).Value = int.Parse(dt.Rows[i][j].ToString());
sd = dt.Rows[i][j + 1].ToString();
if (dt.Rows[i][j + 1].ToString() !="")
ss = sd.Substring(0, 10);
cm3.Parameters.Add("@D", SqlDbType.NChar).Value = ss;
j++;
cm3.Connection.Open();
cm3.ExecuteNonQuery();
}
ss = sd = "";
}
cnd.getcn().Close();
this.Cursor = Cursors.Default;
MessageBox.Show("فایل اضافه شد");
cnd.getcn().Close();
viewG();
}