Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/55.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 将查询取消为字节数组_C#_Mysql - Fatal编程技术网

C# 将查询取消为字节数组

C# 将查询取消为字节数组,c#,mysql,C#,Mysql,我试图以字节数组的形式检索查询。我被代码卡住了 byte[] temp = QueryFile("SELECT modelFile FROM items WHERE modelName='F_Pants1'"); public byte[] QueryFile(string queue) { MySqlCommand command = MySqlCon.CreateCommand(); MySqlD

我试图以字节数组的形式检索查询。我被代码卡住了

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();
        }

你把事情弄得太复杂了。请尝试以下方法:

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

将完成的sql查询接受为字符串的函数将导致sql注入安全问题。如果函数将获得未检查的字符串,则sql注入。将完成的sql查询接受为字符串的函数将导致sql注入安全问题。如果函数将获得未检查的字符串,则sql注入。这也太复杂了-他可以直接使用。ExecuteScalaril稍后更改函数,但在我查询时返回null。这也太复杂了-他可以直接使用。ExecuteScalaril稍后更改函数,但在我查询时返回null