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