Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Friday, June 21, 2019 5:34 PM
Good afternoon,
I'm trying to get the time formatted in hh:mm tt format. For example 02:30 PM. I have a database called SubJobs, a datagridvew called datagridvew1 and a column in SubJobs called Time which is a Time(7) datatype.
This is the query I tried:
string query2 = "select chName, MassType, Date, Time, Stipend from SubList where chID= '" + Person.churchID.ToString() + "'; ";
This is the code I tried to format the column in DataGridView:
dataGridView1.Columns[3].DefaultCellStyle.Format = "hh:mm tt";
When I execute the code I get the following message:
Any help would be greatly appreciated!
Thanks,
Steven
All replies (1)
Friday, June 21, 2019 6:34 PM
Hello,
Here is a mock up w/o a database. If the column coming from the database table is not a date time then that would be the issue.
var dt = new DataTable();
dt.Columns.Add(new DataColumn() {ColumnName = "SomeDate", DataType = typeof(DateTime)});
dt.Rows.Add(DateTime.Now);
dt.Rows.Add();
dt.Rows.Add(DateTime.Now.AddDays(1));
dataGridView1.DataSource = dt;
dataGridView1.Columns[0].DefaultCellStyle.Format = "hh:mm tt";
Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
NuGet BaseConnectionLibrary for database connections.