Specified cast is not valid
-
Hi, I am using VS.Net 2002 edition with the 1.1 framework both at University and at home (my home copy is from University using the University licence so I presume is exactly the same) I have created a front-end application for SQLite (an open source DBMS) which creates databases for users with no SQL knowledge. I link to the DBMS using a .dll file. When I fill a dataset with the contents of a table at University it works fine then goes onto fill a datagrid with this information. Yet when I run the same application at home I get a "Specified cast is not valid" error. Not one thing changes to the application, the data in the table, the .dll file, everything is the same in the two instances yet one works and the other doesn't. Does anyone know what is wrong, if I need to change a setting or install an update on my home PC or something? Any help is greatly appreciated. I have included my code and highlighted where the error shows up although I do not believe my code to be the problem as like I said it works on the University PC's. Many thanks John Code for populating dataset and datagrid
Private Sub cmbInsertData_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbInsertData.SelectedIndexChanged Dim dset As DataSet '= New DataSet() If Len(cmbInsertData.SelectedItem) < 1 Then MessageBox.Show("Please choose a table to view") Else Try tblName = (cmbInsertData.Text) setTableName(tblName) dbConn.openExistingDatabse("Data Source=" & getDBName() & ";Version=3;New=False;Compress=True;") dbConn.createSQLCommand() Try dset = dbConn.selectAll("SELECT * FROM " & tblName, tblName) Catch es As Exception MessageBox.Show("error here -" & es.Message) End Try StoreDataSet.setDataSet(dset) DataGrid1.DataSource = dset.Tables(0).DefaultView Catch es As Exception MessageBox.Show(es.Message) End Try End If End Sub
Public Function selectAll(ByVal strSQL As String, ByVal tableName As String) Dim dset As DataSet = New DataSet() sqlite_cmd.CommandText = (strSQL) sqlite_datareader = sqlite_cmd.ExecuteReader() Dim sqlite_dataAdapter As SQLiteDataAdapter = New SQLiteDataAdapter(strSQL, sqlite_conn) sqlite_co
-
Hi, I am using VS.Net 2002 edition with the 1.1 framework both at University and at home (my home copy is from University using the University licence so I presume is exactly the same) I have created a front-end application for SQLite (an open source DBMS) which creates databases for users with no SQL knowledge. I link to the DBMS using a .dll file. When I fill a dataset with the contents of a table at University it works fine then goes onto fill a datagrid with this information. Yet when I run the same application at home I get a "Specified cast is not valid" error. Not one thing changes to the application, the data in the table, the .dll file, everything is the same in the two instances yet one works and the other doesn't. Does anyone know what is wrong, if I need to change a setting or install an update on my home PC or something? Any help is greatly appreciated. I have included my code and highlighted where the error shows up although I do not believe my code to be the problem as like I said it works on the University PC's. Many thanks John Code for populating dataset and datagrid
Private Sub cmbInsertData_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbInsertData.SelectedIndexChanged Dim dset As DataSet '= New DataSet() If Len(cmbInsertData.SelectedItem) < 1 Then MessageBox.Show("Please choose a table to view") Else Try tblName = (cmbInsertData.Text) setTableName(tblName) dbConn.openExistingDatabse("Data Source=" & getDBName() & ";Version=3;New=False;Compress=True;") dbConn.createSQLCommand() Try dset = dbConn.selectAll("SELECT * FROM " & tblName, tblName) Catch es As Exception MessageBox.Show("error here -" & es.Message) End Try StoreDataSet.setDataSet(dset) DataGrid1.DataSource = dset.Tables(0).DefaultView Catch es As Exception MessageBox.Show(es.Message) End Try End If End Sub
Public Function selectAll(ByVal strSQL As String, ByVal tableName As String) Dim dset As DataSet = New DataSet() sqlite_cmd.CommandText = (strSQL) sqlite_datareader = sqlite_cmd.ExecuteReader() Dim sqlite_dataAdapter As SQLiteDataAdapter = New SQLiteDataAdapter(strSQL, sqlite_conn) sqlite_co
What you need to find out is what is getting casted? What is it? What is it being cast to? At the moment you catch the exception and throw away all the good information.
* Developer Day Scotland: are you interested in speaking or attending? My: Website | Blog
-
What you need to find out is what is getting casted? What is it? What is it being cast to? At the moment you catch the exception and throw away all the good information.
* Developer Day Scotland: are you interested in speaking or attending? My: Website | Blog
-
Hi Colin, I am not really sure what you mean, how do I get all the other good information? I have been taught this way at University so as not to crash out the program. What I find odd is that it can work on one machine and not the other.
Do you have a missing reference? The machine at Uni may have a DLL that is not present on your machine or you may need to set up the reference again if it is a different location or version. Steve
-
Do you have a missing reference? The machine at Uni may have a DLL that is not present on your machine or you may need to set up the reference again if it is a different location or version. Steve
-
Hi Steve, I have tried re-referencing all the references which are present, this does not fix the error. Is there anyway I could find out what DLL could be missing or should I just leave it and be thankful it works at University? John
You should be notified in the Task List if your project detects a missing reference. What line of code is causing the error? It is not highlited as you stated in your original post. Steve
-
Hi Colin, I am not really sure what you mean, how do I get all the other good information? I have been taught this way at University so as not to crash out the program. What I find odd is that it can work on one machine and not the other.
newbjohny wrote:
I have been taught this way at University so as not to crash out the program.
Your try/catch blocks here are being used for debugging purposes not to prevent the application from crashing. Using try/catch for debugging is a waste of time when there are better tools available. Did your university not teach you how to set breakpoints and step through code and how to watch variables? You need to find out the full stack trace of where the exception was thrown. By catching the exception and displaying only the message you've thrown all that information away - get rid of the try/catch and see where the application actaully crashes. When it does the Visual Studio debugger will show you exactly where the crash is (even if it is in code you did not write) If you are missing a referrence your application is unlikely to compile on your home machine.
* Developer Day Scotland: are you interested in speaking or attending? My: Website | Blog
-
You should be notified in the Task List if your project detects a missing reference. What line of code is causing the error? It is not highlited as you stated in your original post. Steve
I get the impression that his code is compiling. The message he mentions suggests that he has got the code running. A missing referrence would mean the code wouldn't compile. Of course, he could be running the binaries he compiled at uni'.
* Developer Day Scotland: are you interested in speaking or attending? My: Website | Blog
-
I get the impression that his code is compiling. The message he mentions suggests that he has got the code running. A missing referrence would mean the code wouldn't compile. Of course, he could be running the binaries he compiled at uni'.
* Developer Day Scotland: are you interested in speaking or attending? My: Website | Blog
Yes. I agree. Just a thought... Steve
-
You should be notified in the Task List if your project detects a missing reference. What line of code is causing the error? It is not highlited as you stated in your original post. Steve
No I am not notified of a missing reference, sorry, I did highlight the line but then when I put the code in code tags it must have got rid of the bold, the line that causes the error is this one :- dset = dbConn.selectAll("SELECT * FROM " & tblName, tblName) John
-
newbjohny wrote:
I have been taught this way at University so as not to crash out the program.
Your try/catch blocks here are being used for debugging purposes not to prevent the application from crashing. Using try/catch for debugging is a waste of time when there are better tools available. Did your university not teach you how to set breakpoints and step through code and how to watch variables? You need to find out the full stack trace of where the exception was thrown. By catching the exception and displaying only the message you've thrown all that information away - get rid of the try/catch and see where the application actaully crashes. When it does the Visual Studio debugger will show you exactly where the crash is (even if it is in code you did not write) If you are missing a referrence your application is unlikely to compile on your home machine.
* Developer Day Scotland: are you interested in speaking or attending? My: Website | Blog
Hi, sadly they did not teach us to do anything other that the try and catch, to be honest they never really taught us, all the lecture notes were ripped straight from the recommended text book. Anyway thats a aside issue. I've taken out the try-catch and it still crashes out with the same error, but two lines of code are highlighted, the one mentioned earlier in the form :- dset = dbConn.selectAll("SELECT * FROM " & tblName, tblName) and one in selectAll function in the connection class:- sqlite_dataAdapter.Fill(dset, tableName) A third line is highlighted in dissassembly but I have no idea what this is :- 00000014 mov ecx,eax
-
No I am not notified of a missing reference, sorry, I did highlight the line but then when I put the code in code tags it must have got rid of the bold, the line that causes the error is this one :- dset = dbConn.selectAll("SELECT * FROM " & tblName, tblName) John
What is 'dbConn'? I'm confused how selectAll is a method of dbConn... Steve
-
Hi, sadly they did not teach us to do anything other that the try and catch, to be honest they never really taught us, all the lecture notes were ripped straight from the recommended text book. Anyway thats a aside issue. I've taken out the try-catch and it still crashes out with the same error, but two lines of code are highlighted, the one mentioned earlier in the form :- dset = dbConn.selectAll("SELECT * FROM " & tblName, tblName) and one in selectAll function in the connection class:- sqlite_dataAdapter.Fill(dset, tableName) A third line is highlighted in dissassembly but I have no idea what this is :- 00000014 mov ecx,eax
Ignore the disassembly - what is in the call stack? It should be in the lower half of the Visual Studio window. (Use the following to show it if it is not displayed: Debug-->Windows-->Call Stack)
newbjohny wrote:
dset = dbConn.selectAll("SELECT * FROM " & tblName, tblName)
What is dbConn? I would assume it is a connection, but selectAll is (1) Not a standard method on a connection class and (2) does not conform to the .NET naming guidelines so it may have been written by someone with a Java background.
* Developer Day Scotland: are you interested in speaking or attending? My: Website | Blog
-
Hi, I am using VS.Net 2002 edition with the 1.1 framework both at University and at home (my home copy is from University using the University licence so I presume is exactly the same) I have created a front-end application for SQLite (an open source DBMS) which creates databases for users with no SQL knowledge. I link to the DBMS using a .dll file. When I fill a dataset with the contents of a table at University it works fine then goes onto fill a datagrid with this information. Yet when I run the same application at home I get a "Specified cast is not valid" error. Not one thing changes to the application, the data in the table, the .dll file, everything is the same in the two instances yet one works and the other doesn't. Does anyone know what is wrong, if I need to change a setting or install an update on my home PC or something? Any help is greatly appreciated. I have included my code and highlighted where the error shows up although I do not believe my code to be the problem as like I said it works on the University PC's. Many thanks John Code for populating dataset and datagrid
Private Sub cmbInsertData_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbInsertData.SelectedIndexChanged Dim dset As DataSet '= New DataSet() If Len(cmbInsertData.SelectedItem) < 1 Then MessageBox.Show("Please choose a table to view") Else Try tblName = (cmbInsertData.Text) setTableName(tblName) dbConn.openExistingDatabse("Data Source=" & getDBName() & ";Version=3;New=False;Compress=True;") dbConn.createSQLCommand() Try dset = dbConn.selectAll("SELECT * FROM " & tblName, tblName) Catch es As Exception MessageBox.Show("error here -" & es.Message) End Try StoreDataSet.setDataSet(dset) DataGrid1.DataSource = dset.Tables(0).DefaultView Catch es As Exception MessageBox.Show(es.Message) End Try End If End Sub
Public Function selectAll(ByVal strSQL As String, ByVal tableName As String) Dim dset As DataSet = New DataSet() sqlite_cmd.CommandText = (strSQL) sqlite_datareader = sqlite_cmd.ExecuteReader() Dim sqlite_dataAdapter As SQLiteDataAdapter = New SQLiteDataAdapter(strSQL, sqlite_conn) sqlite_co
newbjohny wrote:
Private Sub cmbInsertData_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbInsertData.SelectedIndexChanged
newbjohny wrote:
Public Function selectAll(ByVal strSQL As String, ByVal tableName As String)
Are these two methods on the same class? -- modified at 12:04 Saturday 5th August, 2006 What are the fields (aka member variables) on the class(es)?
* Developer Day Scotland: are you interested in speaking or attending? My: Website | Blog
-
What is 'dbConn'? I'm confused how selectAll is a method of dbConn... Steve
dbConnection is a class I created with all functions in that deal with the database. In the forms I want to connect to the database I put this line of code:- Dim dbConn As dbConnection = New dbConnection() selectAll is a function I created to select all from the given table name, put the contents into a dataSet and display in a DataGrid.
-
Ignore the disassembly - what is in the call stack? It should be in the lower half of the Visual Studio window. (Use the following to show it if it is not displayed: Debug-->Windows-->Call Stack)
newbjohny wrote:
dset = dbConn.selectAll("SELECT * FROM " & tblName, tblName)
What is dbConn? I would assume it is a connection, but selectAll is (1) Not a standard method on a connection class and (2) does not conform to the .NET naming guidelines so it may have been written by someone with a Java background.
* Developer Day Scotland: are you interested in speaking or attending? My: Website | Blog
The previous two messages I wrote were from the Call stack. dbConnection is a class I created with all functions in that deal with the database. In the forms I want to connect to the database I put this line of code:- Dim dbConn As dbConnection = New dbConnection() selectAll is a function I created to select all from the given table name, put the contents into a dataSet and display in a DataGrid.
-
dbConnection is a class I created with all functions in that deal with the database. In the forms I want to connect to the database I put this line of code:- Dim dbConn As dbConnection = New dbConnection() selectAll is a function I created to select all from the given table name, put the contents into a dataSet and display in a DataGrid.
What is the definition of this 'selectAll' method? Steve
-
newbjohny wrote:
Private Sub cmbInsertData_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbInsertData.SelectedIndexChanged
newbjohny wrote:
Public Function selectAll(ByVal strSQL As String, ByVal tableName As String)
Are these two methods on the same class? -- modified at 12:04 Saturday 5th August, 2006 What are the fields (aka member variables) on the class(es)?
* Developer Day Scotland: are you interested in speaking or attending? My: Website | Blog
-
What is the definition of this 'selectAll' method? Steve
This is the selectAll code, I just called it selectAll(select *) as that is what I am doing from the database, selecting all from a table and displaying it to the user.
Public Function selectAll(ByVal strSQL As String, ByVal tableName As String) Dim dset As DataSet = New DataSet() sqlite_cmd.CommandText = (strSQL) sqlite_datareader = sqlite_cmd.ExecuteReader() Dim sqlite_dataAdapter As SQLiteDataAdapter = New SQLiteDataAdapter(strSQL, sqlite_conn) sqlite_commandBuilder = New SQLiteCommandBuilder(sqlite_dataAdapter) sqlite_dataAdapter.Fill(dset, tableName) Return dset End Function
-
This is the selectAll code, I just called it selectAll(select *) as that is what I am doing from the database, selecting all from a table and displaying it to the user.
Public Function selectAll(ByVal strSQL As String, ByVal tableName As String) Dim dset As DataSet = New DataSet() sqlite_cmd.CommandText = (strSQL) sqlite_datareader = sqlite_cmd.ExecuteReader() Dim sqlite_dataAdapter As SQLiteDataAdapter = New SQLiteDataAdapter(strSQL, sqlite_conn) sqlite_commandBuilder = New SQLiteCommandBuilder(sqlite_dataAdapter) sqlite_dataAdapter.Fill(dset, tableName) Return dset End Function
Are those sqlite_*** items custom components or your own classes? There is no expected line: Dim sqlite_commandBuilder As SQLiteCommandBuilder What are the 'CommandText' and 'ExecuteReader' lines doing? Nothing as far as I can see... Steve