-1

当数据类型为 varbinary 时如何检索字符代码。它只给出了“System.Byte[]”字符串。这是我的代码:

    public String getTextText(string name)
    {
        DataTable myData = new DataTable();
        SQLiteCommand cmd;
        SQLiteDataAdapter adptr = new SQLiteDataAdapter(); ;
        SQLiteConnection con = new SQLiteConnection("Data Source=database.db;Version=3;New=False;Compress=True;");
        con.Open();
        cmd = con.CreateCommand();
        string sql = "SELECT * FROM parent where name ='" + name + "' ";
        cmd.CommandText = sql;
        adptr.SelectCommand = cmd;
        adptr.Fill(myData);
        con.Close();
        return myData.Rows[0][1].ToString();
    }
4

1 回答 1

1

如此处所述:Varbinary to string

这取决于您首先如何将其插入数据库:

// if the original encoding was ASCII
 return Encoding.ASCII.GetString(myData.Rows[0][1]);

 // if the original encoding was UTF-8
 return Encoding.UTF8.GetString(myData.Rows[0][1]);

 // if the original encoding was UTF-16
 return Encoding.Unicode.GetString(myData.Rows[0][1]);
于 2013-05-10T12:42:34.757 回答