ctype operator in Visual Basic; string to MySqlDateTime
-
Hi I'm having problems due to a cast (*), made by the software automatically, from string to MySqlDateTime; Is there any way of writing the ctype operator for class string, to make the cast to MySqlDateTime ? Can someone give some help??? (*) - the exception apears on a DataGridView, that is connected to a table in a mysql database. I'm already using a CalendarColumn, found somewhere in the web, but as soon as I pick a value, vb throws a exception throgh DataGridView.DataError event, saying: "invalid cast from System.String to MySql.Data.Types.MysqlDateTime"
-
Hi I'm having problems due to a cast (*), made by the software automatically, from string to MySqlDateTime; Is there any way of writing the ctype operator for class string, to make the cast to MySqlDateTime ? Can someone give some help??? (*) - the exception apears on a DataGridView, that is connected to a table in a mysql database. I'm already using a CalendarColumn, found somewhere in the web, but as soon as I pick a value, vb throws a exception throgh DataGridView.DataError event, saying: "invalid cast from System.String to MySql.Data.Types.MysqlDateTime"
Somebody might know the answer to your problem instantly, but for the rest of us, could you post the section of code where the error occurs so that we can suggest alternative strategies. [Edit] Just found this! Take a look at this[^], the relevant part is a fair way down so you'll probably be better off doing a search for mysqldatetime [/Edit]
Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”
modified on Monday, August 24, 2009 8:49 AM
-
Hi I'm having problems due to a cast (*), made by the software automatically, from string to MySqlDateTime; Is there any way of writing the ctype operator for class string, to make the cast to MySqlDateTime ? Can someone give some help??? (*) - the exception apears on a DataGridView, that is connected to a table in a mysql database. I'm already using a CalendarColumn, found somewhere in the web, but as soon as I pick a value, vb throws a exception throgh DataGridView.DataError event, saying: "invalid cast from System.String to MySql.Data.Types.MysqlDateTime"
could not understand exactly your problem but try this field.tostring("dd/mm/yyyy") might solve your problem plus have a look on the following link http://www.wepapers.com/Papers/13639/.NET_Standard_Date_Time_Format_Strings_cheat_sheet[^] http://www.cheat-sheets.org/[^]
Best Of Regards, SOFTDEV Sad like books with torn pages, sad like unfinished stories ...
-
Hi I'm having problems due to a cast (*), made by the software automatically, from string to MySqlDateTime; Is there any way of writing the ctype operator for class string, to make the cast to MySqlDateTime ? Can someone give some help??? (*) - the exception apears on a DataGridView, that is connected to a table in a mysql database. I'm already using a CalendarColumn, found somewhere in the web, but as soon as I pick a value, vb throws a exception throgh DataGridView.DataError event, saying: "invalid cast from System.String to MySql.Data.Types.MysqlDateTime"
I have NO code in my application to handle the input of the date, just the necessary to create the datasource for the datagridview. I use a CalendarColumn to pick a date in the column... When I pick a value for the cell, and I "get out" of the cell, a exception is thrown, and a dialog with the error is displayed: "Invalid cast from System.String to MySql.Data.Types.MySqlDateTime". The call Stack in the message says that the error is thrown in the method PushFormattedValue, that I suppose that cannot be overloaded (or whatever...) PS: Sorry for my english :)
-
I have NO code in my application to handle the input of the date, just the necessary to create the datasource for the datagridview. I use a CalendarColumn to pick a date in the column... When I pick a value for the cell, and I "get out" of the cell, a exception is thrown, and a dialog with the error is displayed: "Invalid cast from System.String to MySql.Data.Types.MySqlDateTime". The call Stack in the message says that the error is thrown in the method PushFormattedValue, that I suppose that cannot be overloaded (or whatever...) PS: Sorry for my english :)
ok, never mind... i think i just solved my problem with this code:
If e.DesiredType.Equals(GetType(MySql.Data.Types.MySqlDateTime)) Then
If String.IsNullOrEmpty(e.Value) Then
e.Value = DBNull.Value
Else
Try
e.Value = New MySql.Data.Types.MySqlDateTime(DateTime.Parse(e.Value))
Catch
e.Value = DBNull.Value
End Try
End If
e.ParsingApplied = True
End Ifin the method
Private Sub DataGridCusto_CellParsing(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellParsingEventArgs) Handles DataGridCusto.CellParsing
thanks
-
ok, never mind... i think i just solved my problem with this code:
If e.DesiredType.Equals(GetType(MySql.Data.Types.MySqlDateTime)) Then
If String.IsNullOrEmpty(e.Value) Then
e.Value = DBNull.Value
Else
Try
e.Value = New MySql.Data.Types.MySqlDateTime(DateTime.Parse(e.Value))
Catch
e.Value = DBNull.Value
End Try
End If
e.ParsingApplied = True
End Ifin the method
Private Sub DataGridCusto_CellParsing(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellParsingEventArgs) Handles DataGridCusto.CellParsing
thanks