Hi all,
I wrote an application in VB 2003 that interfaces with a MS SQL database. When the user performs various tasks (adding/editing/deleting records) a form (containing 1 label) is displayed that shows the status of the task. For instance, when the user opens a form that displays data in a datagrid the message form pops up with the label displays 'Connecting to database...'. Once the connection is made the form displays 'Transfering data...' after the data is transfered and the connection is dropped the form is closed. Here is some sample code:
However, since moving to VB 2005 I have tried to create a similiar message form (a form with 1 label to display the message) which I can't seem to get to work. If I use the same code listed above the status message form causes an error which is:
"Unable to cast object of type 'System.String' to type 'System.Windows.Forms.IWin32Window'."
If I set the text of the label it seems to work, however the status message form will not display any message until after the task has completed and the form only opens for a second before closing (not quick enough to read the message). Does anyone have any idea as to what I need to do in order to get the status message form to display the desired message? Is there a better way to create a message form (I cannot use a status bar on forms due to circumstances beyond my control...)?
Thanks,
jbehrne
If at first you don't succeed, call in an airstrike. - Murphy's Laws of Combat Operations
I wrote an application in VB 2003 that interfaces with a MS SQL database. When the user performs various tasks (adding/editing/deleting records) a form (containing 1 label) is displayed that shows the status of the task. For instance, when the user opens a form that displays data in a datagrid the message form pops up with the label displays 'Connecting to database...'. Once the connection is made the form displays 'Transfering data...' after the data is transfered and the connection is dropped the form is closed. Here is some sample code:
Code:
Private Function SaveRec(ByVal strConn as string, Byval sqlString as string) As Boolean
Dim frmStatusMessage As New frmStatus 'status message form
Dim Conn As SqlConnection
Dim objInsert As SqlCommand
Try
'display message screen
frmStatusMessage.Show("Saving Record")
'connect and run the query
Conn = New SqlConnection(strConn)
Conn.Open()
objInsert = New SqlCommand(sqlString, Conn)
objInsert.ExecuteNonQuery()
Conn.Close()
objInsert.Dispose()
Conn.Dispose()
Catch ex As Exception
SaveRec = False
MsgBox("ERROR")
Conn.Dispose()
frmStatusMessage.Close()
Exit Function
End Try
frmStatusMessage.Close()
SaveRec= True
End Function
However, since moving to VB 2005 I have tried to create a similiar message form (a form with 1 label to display the message) which I can't seem to get to work. If I use the same code listed above the status message form causes an error which is:
"Unable to cast object of type 'System.String' to type 'System.Windows.Forms.IWin32Window'."
If I set the text of the label it seems to work, however the status message form will not display any message until after the task has completed and the form only opens for a second before closing (not quick enough to read the message). Does anyone have any idea as to what I need to do in order to get the status message form to display the desired message? Is there a better way to create a message form (I cannot use a status bar on forms due to circumstances beyond my control...)?
Thanks,
jbehrne
If at first you don't succeed, call in an airstrike. - Murphy's Laws of Combat Operations