I have a datagridview that I want when I select some information contained in the table of my MySQL database, I return the values to the respective text boxes and comboboxes and datetiemepicker, but I receive this exception.
System.FormatException was unhandled
HResult=-2146233033
Message=String was not recognized as a valid DateTime.
Source=mscorlib
StackTrace:
at System.DateTimeParse.Parse(String s, DateTimeFormatInfo dtfi, DateTimeStyles styles)
at System.Convert.ToDateTime(String value)
at Proyecto_final1.Worktable.dgvUsuario_CellContentClick(Object sender, DataGridViewCellEventArgs e) in D:\Manejador de items\Proyecto final1\Proyecto final1\Worktable.cs:line 143
at System.Windows.Forms.DataGridView.OnCellContentClick(DataGridViewCellEventArgs e)
at System.Windows.Forms.DataGridView.OnCommonCellContentClick(Int32 columnIndex, Int32 rowIndex, Boolean doubleClick)
at System.Windows.Forms.DataGridViewCell.OnMouseUpInternal(DataGridViewCellMouseEventArgs e)
at System.Windows.Forms.DataGridView.OnCellMouseUp(DataGridViewCellMouseEventArgs e)
at System.Windows.Forms.DataGridView.OnMouseUp(MouseEventArgs e)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.DataGridView.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at Proyecto_final1.Program.Main() in D:\Manejador de items\Proyecto final1\Proyecto final1\Program.cs:line 19
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:
Finally, here I leave my lines of code.
The last two lines are the Combobox and the datetimepicker respectively.
txtCont.Text = dgvUsuario[0, dgvUsuario.CurrentRow.Index].Value.ToString();
txtUsu.Text = dgvUsuario[1, dgvUsuario.CurrentRow.Index].Value.ToString();
txtNomUsu.Text = dgvUsuario[2, dgvUsuario.CurrentRow.Index].Value.ToString();
txtDirecUsu.Text = dgvUsuario[3, dgvUsuario.CurrentRow.Index].Value.ToString();
txtTelUsu.Text = dgvUsuario[4, dgvUsuario.CurrentRow.Index].Value.ToString();
txtCorreoUsu.Text = dgvUsuario[5, dgvUsuario.CurrentRow.Index].Value.ToString();
CbNivelSeguri.Text = dgvUsuario[6, dgvUsuario.CurrentRow.Index].Value.ToString();
DTPIniUsu.Value = Convert.ToDateTime(dgvUsuario[7, dgvUsuario.CurrentRow.Index].Value.ToString());