I am having a awful time trying to figure out how to update/insert/delete rows from the datasource.
My main program is employee clock in/clock out timesheet (which is done) I am now working on the managers applications which I'm allowing them to insert/update/delete the times the employee clocked in or out. I am using the DataGrid to try and accomplish this but having no luck.
Here is my hours form which I grab the employee ID from the parent form from a combobox.
I would like to know how I can update/delete/insert rows using the DataGrid. I have searched and read a lot throughout google/msdn docs with no success and hoping fellow programmers here could help me out. Also I store the times they clock in/out in a unix timestamp and was looking for a way of validating or converting from datetime to a unix timestamp before it inserts/updates the table.
public partial class Hours : Form
public Hours(int intEid)
// Connect to the database
DbWrapper myWrapper = new DbWrapper();
// Populate datagrid with data in the new dataset
MySqlDataAdapter MyDA = new MySqlDataAdapter();
DataSet dsDept = new DataSet();
string sqlDept = "SELECT FROM_UNIXTIME(time_in), FROM_UNIXTIME(time_out) FROM records WHERE eid = " + intEid + " AND FROM_UNIXTIME(time_in) >= (CONCAT( DATE_SUB(CURDATE(), INTERVAL WEEKDAY(DATE_SUB(CURDATE(), INTERVAL 4 DAY)) DAY), ' 00:00:00'))";
MyDA.SelectCommand = new MySqlCommand(sqlDept, myWrapper.getSqlConn());
// Populate a new data table and bind it to the BindingSource.
DataTable table = new DataTable();
table.Locale = System.Globalization.CultureInfo.InvariantCulture;
dbBindSource.DataSource = table;
// finally bind the data to the grid
dataGridView.DataSource = dbBindSource;
dataGridView.Columns.HeaderText = "Time In";
dataGridView.Columns.Width = 150;
dataGridView.Columns.HeaderText = "Time Out";
dataGridView.Columns.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
// disconnect from the database
// close this form
private void btnClose_Click(object sender, EventArgs e)
Thanks for any help!
Also if I am going about this the wrong way and there is another way to do it I am open for suggestions.