Specified cast is not valid
-
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
-
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
Hi Steve, the sqlite_*** are my names I've given to them. Like in the code above, I've simply added the _ so when I come to use it elsewhere I know what it is, so SQLiteCommandBuilder becomes sqilte_commandBuilder. It's just easier for me. They come from a 3rd party wrapper which is finisar.sqlite which can be found at http://adodotnetsqlite.sourceforge.net/ the expected line of "Dim sqlite_commandBuilder As SQLiteCommandBuilder" is present and has been declared at the top of the dbConnection class with all the other things that need declaring. Now that you mention it I don't know what those two lines are doing, they are there from when I started this project a long time ago and as it was working I never took anything out. I've took them out and they makeno difference to the error messge so it looks as if they were not needed at all. -- modified at 12:47 Saturday 5th August, 2006
-
Hi Steve, the sqlite_*** are my names I've given to them. Like in the code above, I've simply added the _ so when I come to use it elsewhere I know what it is, so SQLiteCommandBuilder becomes sqilte_commandBuilder. It's just easier for me. They come from a 3rd party wrapper which is finisar.sqlite which can be found at http://adodotnetsqlite.sourceforge.net/ the expected line of "Dim sqlite_commandBuilder As SQLiteCommandBuilder" is present and has been declared at the top of the dbConnection class with all the other things that need declaring. Now that you mention it I don't know what those two lines are doing, they are there from when I started this project a long time ago and as it was working I never took anything out. I've took them out and they makeno difference to the error messge so it looks as if they were not needed at all. -- modified at 12:47 Saturday 5th August, 2006
Well, I'm at a loss my friend! The only other thing I can see is the line: Dim dset As DataSet is repeated in 'cmbInsertData_SelectedIndexChanged' and in your 'selectAll' function. Don't know if that would cause an error... I suspect it has something to do with one of your third party components. Maybe one of them is corrupted or something. Good luck! Steve
-
Well, I'm at a loss my friend! The only other thing I can see is the line: Dim dset As DataSet is repeated in 'cmbInsertData_SelectedIndexChanged' and in your 'selectAll' function. Don't know if that would cause an error... I suspect it has something to do with one of your third party components. Maybe one of them is corrupted or something. Good luck! Steve
-
It's very weird as you would suspect it to either work on both my home and Uni PC's or neither, not to work on one and not the other. Anyway thanks for your help and suggestions, they were very much appreciated. Thanks again John
Yes. This really suggests it is something other than your code. Steve
-
Yes. This really suggests it is something other than your code. Steve
-
No, the function is in a dbConnection class and the cmbinsertdata is on a form. I'm sorry but I do not know what a member variable is. Is there someway I could zip my code and email it to you, it may be easier if you could see the code. John
newbjohny wrote:
I'm sorry but I do not know what a member variable is.
:omg: Do they teach you anything at this university? member variable, also known as a class field, for example:
public class SomeClass
{
// the following is a field
private int someMemberVariable;
}It is a variable that exists within the scope of an instance of a class. All methods and properties in the class can access the variable. You might want to invest in a couple of books that the university did not recommend.
* Developer Day Scotland: are you interested in speaking or attending? My: Website | Blog
-
newbjohny wrote:
I'm sorry but I do not know what a member variable is.
:omg: Do they teach you anything at this university? member variable, also known as a class field, for example:
public class SomeClass
{
// the following is a field
private int someMemberVariable;
}It is a variable that exists within the scope of an instance of a class. All methods and properties in the class can access the variable. You might want to invest in a couple of books that the university did not recommend.
* Developer Day Scotland: are you interested in speaking or attending? My: Website | Blog
Ive just never heard them be called this before, in the dbConnection class there is :- Public tableNames() As String Public indexNames() As String Public triggerNames() As String Public viewNames() As String Public columnNames As New ArrayList() Public columnTypes As New ArrayList() Dim tables, i As Integer Dim sqlite_conn As SQLiteConnection Dim sqlite_cmd As SQLiteCommand Dim sqlite_datareader As SQLiteDataReader Dim sqlite_dataAdapter As SQLiteDataAdapter Dim dset As DataSet = New DataSet() Dim sqlite_commandBuilder As SQLiteCommandBuilder Private data_Table As New DataTable() Private rowPos As Integer = 0 in the viewdata form there is :- Dim dbConn As dbConnection = New dbConnection() Dim tableName As String Dim tblName As String
-
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 is this? tblName = (cmbInsertData.Text) setTableName(tblName) I do not see a declaration of the Variable tblName ( Dim tblName as String ). I believe VB will create this as an Object type without the Dim statment, and then you are trying to us it as a string? what is setTableName? are you expecting the variable tblName to change when it comes out of setTableName? Step thru the code line for line in debug and you can see exactly what all your variables are and what might be missing. Joe -- modified at 0:37 Sunday 6th August, 2006
-
What is this? tblName = (cmbInsertData.Text) setTableName(tblName) I do not see a declaration of the Variable tblName ( Dim tblName as String ). I believe VB will create this as an Object type without the Dim statment, and then you are trying to us it as a string? what is setTableName? are you expecting the variable tblName to change when it comes out of setTableName? Step thru the code line for line in debug and you can see exactly what all your variables are and what might be missing. Joe -- modified at 0:37 Sunday 6th August, 2006
Hi Joe, I have declared tblName as a String at the top of the form as it is used a few times throughout the form. setTableName(tblName) is a method within a Module I created to store the name of the table in the database I am using so that I can use it in another form with the method getTableName. I've looked through and can't find any errors, like I said before it works fine at University. I emailed someone my project from another forum and they said it worked fine on their pc also so were unsure as the problem, theyve uploaded it to the forum if anyone wants to download it and look at the code first hand they can. It is message 12 by user "doWhileSomething" and the program is in the link Program, the forum is at :- http://www.vbcity.com/forums/topic.asp?tid=131204&page=2&#RID424741
-
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