private void testButton_Click(object sender, EventArgs e)
{
try
{
//Create OleDB connection
OleDbConnection connection = new OleDbConnection();
connection.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0; Data Source=I:\PSC SHARED\accessdb.accdb;
Persist Security Info=False;";
//connect to DB
connection.Open();
//Setup
var ComboBoxList = Controls.OfType<ComboBox>();
OleDbCommand command = new OleDbCommand();
command.Connection = connection;
//Insert data into table through loop
foreach(ComboBox taskComboBox in ComboBoxList)
{
string query = "INSERT INTO MasterTable(Task, TimeWorked, RefDate, Analyst, HoursWorked) values('" + taskComboBox.Text + "', '" + stopwatch1.Elapsed.ToString("hh\\:mm\\:ss") + "', '" + ReferenceDate + "', '" + AnalystName + "', '" + (stopwatch1.Elapsed.TotalMinutes / 60d).ToString("N2") + "')";
command.CommandText = query;
command.ExecuteNonQuery();
}
//close connection to db
connection.Close();
}
//handle errors
catch (Exception ex)
{
MessageBox.Show("Error: " + ex);
}
}
Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.
When asked, what has been your best career decision?
Deciding to stick with EE.
Being involved with EE helped me to grow personally and professionally.
Connect with Certified Experts to gain insight and support on specific technology challenges including:
We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE