private void t_submit_result_Click(object sender, EventArgs e) { try { OpenFileDialog ope = new OpenFileDialog(); ope.Filter = "Excel Files|*.xls;*.xlsx;*.xlsm*"; if (ope.ShowDialog() == DialogResult.Cancel) { return; } FileStream stream = new FileStream(ope.FileName, FileMode.Open); IExcelDataReader excelReader = ExcelReaderFactory.CreateOpenXmlReader(stream); DataSet result = excelReader.AsDataSet(); DataClasses1DataContext conn = new DataClasses1DataContext(); foreach (DataTable table in result.Tables) { foreach (DataRow dr in table.Rows) { marks_tbl addtable = new marks_tbl() { student_id = Convert.ToString(dr[0]), quiz = Convert.ToInt32(dr[1]), class_performance = Convert.ToInt32(dr[2]), final = Convert.ToInt32(dr[3]), total = Convert.ToInt32(dr[4]), grade = Convert.ToString(dr[5]), }; conn.marks_tbls.InsertOnSubmit(addtable); } } //String stringconn = "provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + textBox1.Text + ";Extended Properties=\"Excel 8.0;HDR=Yes;\"; conn.SubmitChanges(); excelReader.Close(); stream.Close(); MessageBox.Show("successfull"); } catch (Exception ex) { //sqlConnection.Close(); MessageBox.Show("This file is already in the database!"); } }
partial void Updatemarks_tbl(marks_tbl instance);
partial void Deletemarks_tbl(marks_tbl instance);
partial void Insertmarks_tbl(marks_tbl instance);