当数据类型为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();
}
答案 0 :(得分: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]);