Link to home
Start Free TrialLog in
Avatar of Olukayode Oluwole
Olukayode OluwoleFlag for Canada

asked on

What is the correct syntax to read a date field from a grid

I have a c# application reading 2 date fields from a grid

with the script below

[public DataTable GetResultsTable()                  //  This handles Insertion of Grid items  into database
        {
            DataTable d =  (DataTable)(dgvDetailsTable.DataSource);

                foreach (DataGridViewRow row in dgvDetailsTable.Rows)
                {
                    //if (Convert.ToString(row.Cells["dgvtxtCompName"].Value).Length > 0)
                    //{
                    (string gc2, DateTime gc3, DateTime gc4, string gc5, string gc6) = (
                              GridVariables.GridColumn02 = gc2 = Convert.ToString(row.Cells["dgvtxtCompName"].Value),
                              GridVariables.GridColumn03 = gc3 = Convert.ToDateTime(row.Cells["dgvstartdate"].Value),
                              GridVariables.GridColumn04 = gc4 = Convert.ToDateTime(row.Cells["dgvenddate"].Value),
                              GridVariables.GridColumn05 = gc5 = Convert.ToString(row.Cells["dgvtxtyearsexp"].Value),
                              GridVariables.GridColumn06 = gc6 = Convert.ToString(row.Cells["dgvtxtPosition"].Value)
                               );
     
                    GlobalConfig.Connection.CreateJobHistoryForm((DataTable)dgvDetailsTable.DataSource);

                }
                MessageBox.Show("Records saved to Database", "NEW RECORDS CREATION !!!", MessageBoxButtons.OK);
                WireupList2();
                return d;
       
        }[/code]

The 2 date fields  startdate  and enddate contain    1-11-2019  and 30-11-2019

I have used the debugger to confirm that the fields actually contain these  values

However  i think the script expects a different syntax for the 2 fields being read.

The error screen is shown below

User generated image
What would be the correct syntax to ensure that the date field as read is acceptable

Any help will be appreciated

Olukay
Avatar of Eduard Ghergu
Eduard Ghergu
Flag of Romania image

Hi,

Could you dump the string values from the cells using Debug.Write and see if they're ok?
Avatar of Olukayode Oluwole

ASKER

I am sorry i don't understand what you want me to do.

I have debugged and can see that the date values are correct

What does it mean to dump the values and then write . How  do i do that

Grateful for an example

Thanks

Olukay
HI,

Add the following lines in the beginning of the foreach loop body:
 
Debug.WriteLine(row.Cells["dgvstartdate"].Value);
Debug.WriteLine(row.Cells["dgvenddate"].Value);

Execute the code and paste here what is shown in the VS Debug pane.
Find what was pasted  after the first debug line
User generated image
then after the second debug line
User generated image
and finally error  going into the original script
User generated image
I hope the above helpto resolve the issue

Olukay
ASKER CERTIFIED SOLUTION
Avatar of Eduard Ghergu
Eduard Ghergu
Flag of Romania image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks
Hi!
My pleasure! If you need more help, please, let me know!