advertisement

Search | Recent | Register

Forum => General ASP.NET => Specified cast is not valid

Jump to:

Next Oldest | Next Newest

6/8/2006 7:03:14 AM Link | Reply | Edit | Quote

newbjohny

Profile Send Private Message
Location: | Joined: 6/8/2006 | Posts: 5 | Offline

Hi I am using VB.Net 2002 with the Finisar.SQLite data provider to access the SQLite DBMS. I can access it no problem, insert, delete etc.. all fine. But what I am having trouble with is filling a dataset with the data within the table. I have attached the code I have created in the hope that someone can spot my mistake. I get the following error :- "Specified cast is not valid."

The following is part of a dbConnection.vb class :-

Dim dset As DataSet = New DataSet()

Public Function selectAll(ByVal strSQL As String)
sqlite_cmd.CommandText = (strSQL)
sqlite_datareader = sqlite_cmd.ExecuteReader()

Dim sqlite_dataAdapter As SQLiteDataAdapter = New SQLiteDataAdapter(strSQL, sqlite_conn)

sqlite_dataAdapter.Fill(dset) <<<<-------- Error highlights this line(Specified cast is not valid)

' The SQLiteDataReader allows us to run through the result lines:
While sqlite_datareader.Read()
dset = sqlite_datareader("text")
'MessageBox.Show(sqlite_datareader("text"))
End While
sqlite_datareader.Close()
Return dset
End Function

The following is from a button call to the selectAll function :-

Public Sub btnViewTable_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnViewTable.Click
Dim dset As DataSet


dbConn.openExistingDatabse("Data Source=" & getDBName() & ";Version=3;New=False;Compress=True;")
dbConn.createSQLCommand()

tblName = (cmbInsertData.Text)

dbConn.selectAll("SELECT * FROM " & tblName)

DataGrid1.DataSource = dset.Tables(0).DefaultView

End Sub

6/8/2006 1:39:43 PM Link | Reply | Edit | Quote

Jeff

Profile Send Private Message Web Site AOL Instant Message ICQ Message
Location: Cleveland, OH, USA | Joined: 8/15/2000 | Posts: 813 | Offline

You've got to narrow it down to a line...


Jeff 'Jones' Putz
POP World Media, LLC

6/8/2006 2:46:25 PM Link | Reply | Edit | Quote

newbjohny

Profile Send Private Message
Location: | Joined: 6/8/2006 | Posts: 5 | Offline

I had this line in the code, you must not have saw it, I should have highlighted it better, the line that brings up the error is as follows :-

sqlite_dataAdapter.Fill(dset) <<<<-------- Error highlights this line(Specified cast is not valid)

Many thanks for your help

John

6/8/2006 3:52:07 PM Link | Reply | Edit | Quote

Jeff

Profile Send Private Message Web Site AOL Instant Message ICQ Message
Location: Cleveland, OH, USA | Joined: 8/15/2000 | Posts: 813 | Offline

Well as best I can tell, it's a problem with the data you're getting out of the database. Don't know anything about that DB though. Casting errors occur when you try to make one type into another type. For example, you can't conver the string "hello" to an integer.


Jeff 'Jones' Putz
POP World Media, LLC

6/13/2006 12:56:06 PM Link | Reply | Edit | Quote

newbjohny

Profile Send Private Message
Location: | Joined: 6/8/2006 | Posts: 5 | Offline

Hiya, sorry for the long delay in replying, internet connection went down.

I am only inserting 2 lines of test data at the moment, it used to work but no longer does.

How would I create and fill a dataset then display this data into a datagrid if I was just using the normal data adapter? I can only find books that take you through the wizard but you cannot use the wizard with SQLite data adapter.

If I could find the code to do this then I could check my code with that of this code and see where I may be going wrong.

Many thanks

John

6/13/2006 1:10:08 PM Link | Reply | Edit | Quote

Jeff

Profile Send Private Message Web Site AOL Instant Message ICQ Message
Location: Cleveland, OH, USA | Joined: 8/15/2000 | Posts: 813 | Offline

I don't really know, because I never use data adapters, datasets, datatables, etc. It's all too clumsy for my tastes.


Jeff 'Jones' Putz
POP World Media, LLC

6/13/2006 1:15:11 PM Link | Reply | Edit | Quote

newbjohny

Profile Send Private Message
Location: | Joined: 6/8/2006 | Posts: 5 | Offline

Do you have any other suggestions as to how I could display the data held within my database to the user in a tabular form?

6/13/2006 1:53:28 PM Link | Reply | Edit | Quote

Jeff

Profile Send Private Message Web Site AOL Instant Message ICQ Message
Location: Cleveland, OH, USA | Joined: 8/15/2000 | Posts: 813 | Offline

Well you can bind anything that implements IEnumerable to a DataGrid, so take your pick.


Jeff 'Jones' Putz
POP World Media, LLC

6/15/2006 5:22:27 AM Link | Reply | Edit | Quote

newbjohny

Profile Send Private Message
Location: | Joined: 6/8/2006 | Posts: 5 | Offline

I don't know anything about IEnumerable, I am looking into it now. I dont have much time left for my project(I'm already over schedule) as I have to move onto my dissertation. I may have to just leave it as is and move onto the dissertation as this is worth more marks and if I have time at the end I can come back and try and fix this problem.

Forum => General ASP.NET => Specified cast is not valid