Go Back   CodingForums.com > :: Computing & Sciences > Computer Programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 06-04-2008, 09:34 PM   PM User | #1
devinkray
New Coder

 
Join Date: Jan 2007
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
devinkray is an unknown quantity at this point
C# MySQL and Datagrids...

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.

Code:
namespace MJFinal
{
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using MySql.Data.MySqlClient;
    using CSConnector;
    using Time;

    
    public partial class Hours : Form
    {
        public Hours(int intEid)
        {
            InitializeComponent();

            // Connect to the database
            DbWrapper myWrapper = new DbWrapper();
            myWrapper.Connect();

            // 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;
            MyDA.Fill(table);

            dbBindSource.DataSource = table;

            // finally bind the data to the grid
            dataGridView.DataSource = dbBindSource;

            dataGridView.Columns[0].HeaderText = "Time In";
            dataGridView.Columns[0].Width = 150;
            dataGridView.Columns[1].HeaderText = "Time Out";
            dataGridView.Columns[1].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;


            // disconnect from the database
            myWrapper.Disconnect();

        }

        // close this form
        private void btnClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
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.

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.

Last edited by devinkray; 06-04-2008 at 09:38 PM..
devinkray is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:09 PM.


Advertisement
Log in to turn off these ads.