Olukayode Oluwole
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)(dgvDetailsTabl e.DataSour ce);
foreach (DataGridViewRow row in dgvDetailsTable.Rows)
{
//if (Convert.ToString(row.Cell s["dgvtxtC ompName"]. Value).Len gth > 0)
//{
(string gc2, DateTime gc3, DateTime gc4, string gc5, string gc6) = (
GridVariables.GridColumn02 = gc2 = Convert.ToString(row.Cells ["dgvtxtCo mpName"].V alue),
GridVariables.GridColumn03 = gc3 = Convert.ToDateTime(row.Cel ls["dgvsta rtdate"].V alue),
GridVariables.GridColumn04 = gc4 = Convert.ToDateTime(row.Cel ls["dgvend date"].Val ue),
GridVariables.GridColumn05 = gc5 = Convert.ToString(row.Cells ["dgvtxtye arsexp"].V alue),
GridVariables.GridColumn06 = gc6 = Convert.ToString(row.Cells ["dgvtxtPo sition"].V alue)
);
GlobalConfig.Connection.Cr eateJobHis toryForm(( DataTable) dgvDetails Table.Data Source);
}
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
What would be the correct syntax to ensure that the date field as read is acceptable
Any help will be appreciated
Olukay
with the script below
[public DataTable GetResultsTable() // This handles Insertion of Grid items into database
{
DataTable d = (DataTable)(dgvDetailsTabl
foreach (DataGridViewRow row in dgvDetailsTable.Rows)
{
//if (Convert.ToString(row.Cell
//{
(string gc2, DateTime gc3, DateTime gc4, string gc5, string gc6) = (
GridVariables.GridColumn02
GridVariables.GridColumn03
GridVariables.GridColumn04
GridVariables.GridColumn05
GridVariables.GridColumn06
);
GlobalConfig.Connection.Cr
}
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
What would be the correct syntax to ensure that the date field as read is acceptable
Any help will be appreciated
Olukay
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
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[ "dgvstartd ate"].Valu e);
Debug.WriteLine(row.Cells[ "dgvenddat e"].Value) ;
Execute the code and paste here what is shown in the VS Debug pane.
Add the following lines in the beginning of the foreach loop body:
Debug.WriteLine(row.Cells[
Debug.WriteLine(row.Cells[
Execute the code and paste here what is shown in the VS Debug pane.
ASKER
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks
Hi!
My pleasure! If you need more help, please, let me know!
My pleasure! If you need more help, please, let me know!
Could you dump the string values from the cells using Debug.Write and see if they're ok?