Hey,
So at the moment I can import an excel file into my c# application and view it in a datagridview, next I have rearranged the data into 17 different headings and displayed it in another datagridview and now I am trying to import that into an Access Database, although I am getting no errors the Access database is not being updated and I'm totally stumped:
My code below for updating the access database:
My whole project code:
Any help is hugely appreciated.
So at the moment I can import an excel file into my c# application and view it in a datagridview, next I have rearranged the data into 17 different headings and displayed it in another datagridview and now I am trying to import that into an Access Database, although I am getting no errors the Access database is not being updated and I'm totally stumped:
My code below for updating the access database:
tblEquipmentTableAdapter.Update(sQTDBDataSet);
My whole project code:
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.Data.OleDb; namespace Application { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void label1_Click(object sender, EventArgs e) { } private void label2_Click(object sender, EventArgs e) { } private void button1_Click(object sender, EventArgs e) { foreach (DataRow r in dsEquipment.Tables[0].Rows) { DataRow dr = sQTDBDataSet.tblEquipment.NewRow(); dr[0] = r[0]; dr[1] = r[1]; dr[2] = r[2]; dr[3] = r[3]; dr[4] = r[4]; dr[5] = r[5]; dr[6] = r[6]; dr[7] = r[7]; dr[8] = r[8]; dr[9] = r[9]; dr[10] = r[10]; dr[11] = r[11]; dr[12] = r[12]; dr[13] = r[13]; dr[14] = r[14]; dr[15] = r[15]; dr[16] = r[16]; sQTDBDataSet.tblEquipment.Rows.Add(dr); } tblEquipmentTableAdapter.Update(sQTDBDataSet); //tblEquipmentTableAdapter.Update(SQTDBDataSet); } private void btnReadExcel_Click(object sender, EventArgs e) { // Establish connection between the c# application and the excel file. OleDbConnection con = new OleDbConnection(@"Provider=Microsoft.Ace.OLEDB.12.0;Data Source="+txtFileName.Text+";Extended Properties=Excel 12.0"); // Reading the data from the excel file. OleDbDataAdapter da = new OleDbDataAdapter("select * from [Equipment$]", con); // All data from the file will be loaded into the dataset. da.Fill(dsEquipment); // Show in a message box how many rows of data there is. //MessageBox.Show(dsEquipment.Tables[0].Rows.Count.ToString()); // Show the data in the data grid view. dgEquipment.DataSource = dsEquipment.Tables[0]; } private void dataGridView2_CellContentClick(object sender, DataGridViewCellEventArgs e) { } private void tblEquipmentBindingNavigatorSaveItem_Click(object sender, EventArgs e) { this.Validate(); this.tblEquipmentBindingSource.EndEdit(); this.tableAdapterManager.UpdateAll(this.sQTDBDataSet); } private void Form1_Load(object sender, EventArgs e) { // TODO: This line of code loads data into the 'sQTDBDataSet.tblEquipment' table. You can move, or remove it, as needed. this.tblEquipmentTableAdapter.Fill(this.sQTDBDataSet.tblEquipment); } } }
Any help is hugely appreciated.