简体   繁体   English

C#SQLite查询不返回

[英]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[]". 我尝试在SQLite表上运行查询,但是它没有返回插入的内容,而是返回“ 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): 这是s.executeNormalQuery(字符串查询):

    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. 首先将DataRow 0强制转换为byte [],然后编码为UTF-8。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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