将查询作为字节数组收回 [英] Retireve a query as a byte array

查看:38
本文介绍了将查询作为字节数组收回的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试以字节数组的形式检索查询.不过我还是坚持@代码.

Im trying to retrieve a query as a byte array. Im stuck @ the code though.

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;

            }

如果有人有答案,我将不胜感激.

If anyone has an answer, i would greatly appreciate it.

推荐答案

你让它有点太复杂了.试试这个:

You're making it a bit too complicated. Try this instead:

       try {
         Reader = command.ExecuteReader();
         if (Reader.Read())
          {
              return Reader.GetValue(0) as Byte[];
          }
        } finally {
           MySqlCon.Close();
        }

这篇关于将查询作为字节数组收回的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆