I have a problem I'm trying to import an excel file to mysql database. It's working but it only imports 1 row.
OleDbConnection olconn = new OleDbConnection(conStr);
OleDbDataAdapter myDataAdapter = new OleDbDataAdapter("Select * From [" + comboBox1.Text + "]", olconn);
dt = new DataTable();
DataSet ds = new DataSet();
myDataAdapter.Fill(ds);
olconn.Close();
dataGridView1.DataSource = dt;
//gridControl1.DataSource = dt;
connExcel.Close();
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
MySqlConnection con = new MySqlConnection(connStr);
string query = "Insert into excel(IDExcel, studentnumber, fullname, course, yearandsection) Values('" +
ds.Tables[0].Rows[i][0].ToString() + "','" + ds.Tables[0].Rows[i][1].ToString() + "','" + ds.Tables[0].Rows[i][2].ToString() + "','" + ds.Tables[0].Rows[i][3].ToString() + "','" + ds.Tables[0].Rows[i][4].ToString() + "')";
con.Open();
MySqlCommand cmd = new MySqlCommand(query, con);
cmd.ExecuteNonQuery();
con.Close();
}
MessageBox.Show("Done Importing!", "Congratulations!", MessageBoxButtons.OK,MessageBoxIcon.Information);