将查询检索为字节数组
本文关键字:字节数 数组 字节 查询 检索 | 更新日期: 2023-09-27 18:16:16
我试图检索查询作为字节数组。我在代码上卡住了。
byte[] temp = QueryFile("SELECT modelFile FROM items WHERE modelName='F_Pants1'");
public byte[] QueryFile(string queue)
{
MySqlCommand command = MySqlCon.CreateCommand();
MySqlDataReader Reader;
command.CommandText = queue;
MySqlCon.Open();
Reader = command.ExecuteReader();
byte[] thisrow = new byte[1000];
while (Reader.Read())
{
for (int i = 0; i < Reader.FieldCount; i++)
thisrow[0] = Convert.ToByte(Reader.GetValue(i).ToString());
}
thisrow = thisrow.Remove(thisrow.Length - 1, 1);
MySqlCon.Close();
return thisrow;
}
如果有人有答案,我将不胜感激。
你把它弄得有点太复杂了。试试这个:
try {
Reader = command.ExecuteReader();
if (Reader.Read())
{
return Reader.GetValue(0) as Byte[];
}
} finally {
MySqlCon.Close();
}