简体   繁体   中英

C# SQLite query not return

I have a strange proble. I try to run a query on an SQLite table but it not return the content insted it return "System.Byte[]". This code is run the query and should get the "text" rows content:

    string q = "SELECT text FROM leiras WHERE(id=" + this.id + ");";
    DataTable dt = s.executeNormalQuery(q);
    DataRow dr = dt.Rows[0];
    string content = dr[0].ToString();

This is the s.executeNormalQuery(string query):

    DataTable dt = new DataTable();

    try
    {
        SQLiteConnection con = new SQLiteConnection(this.conURL);
        con.Open();
        SQLiteCommand com = new SQLiteCommand(query, con);
        SQLiteDataReader read = com.ExecuteReader();
        dt.Load(read);
        read.Close();
        con.Close();
    }
    catch (Exception e)
    {
        Console.WriteLine(e.StackTrace);
    }

    return dt;

And the "text" cell in the table is containing

cg0ovnP0w6XyBKxLQq6XaZpxAPw/lHlSx/fRjZSdmuU=

as blob.

Ok thanks i've found it:

    byte[] cont = (byte[]) dr[0];
    string decodedString = System.Text.Encoding.UTF8.GetString(cont);
    Console.WriteLine(decodedString);

First cast DataRow 0 to byte[] then encode to UTF-8.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM