SQLite.NET - Retrieving Data

Ionix

Member
Joined
Oct 18, 2006
Messages
10
Location
Singapore
I am currently using SQLite.NET Wrapper from http://www.phpguru.org/static/SQLite.NET.html

I am currently facing a problem on retrieving the data.
My codes are as below...
C#:
SQLiteResultSet tempResult;
ArrayList tempString;

tempResult = sqlite.Execute("SELECT * FROM MARKET;");

tempString = tempResult.Rows;

for(int i=0; i<tempString.Count; i++)
{
	Debug.Print((String)tempString[i]);
}
I am trying to typecast the tempString which is an ArrayList to String. But receive this error "Unable to cast object of type System.Collections.ArrayList to type System.String."

I am new to C#, please kindly teach me how to convert this?
Thanks.
 
Last edited by a moderator:
I tried

tempString.ToString() //It will print "System.Collections.ArrayList"
(String)tempString //It will give error "System.InvalidCastException"

So what should I do?

tempString is an ArrayList and how do I display its content?
Shouldnt it be tempString?
 
tempString doesnt contain strings - only just looked at your original post, it looks like it contains an array of DataRow objects. Is that right?
 
Code:
using SQLite.NET;

[..]

private SQLiteClient db;

[..]
///
/// Load the database on form load. If the database does not
/// exist the client library will create it for us.
///
private void formMain_Load(object sender, System.EventArgs e)
{
     db = new SQLiteClient(
 
[csharp]
ArrayList row in results.Rows
[/csharp]

Doesnt this sentence mean

For every results.Rows
ArrayList row = results.Rows

?? :confused:
 
tmpString contains an array but it is returned as an object, you will need to cast the result of tmpString to an Arraylist and then access those elements.

Try something like
C#:
((ArrayList) tmpString[i])[0].ToString()
//or more explicit
ArrayList tmp = (ArrayList) tmpString[i];
string s = tmp[0].ToString();
 
Yes you are right finally it works.

So there is a double return of ArrayList... no wander I am unable to convert it to string.

Thanks.

but the example by Nik, doesnt it only takes in 1 ArrayList row for each loop?
how is it possible for that his example to work that way?
 
Back
Top