问题描述
public Byte[] picbox(string p)
{
byte[] binaryData;
connection.Open();
command.CommandText = "select * From adduser where (bakernum=@bakernum)";
command.Parameters.AddWithValue("@bakernum", p);
SqlDataReader reader = command.ExecuteReader();
reader.Read();
if (reader.HasRows)
binaryData = (byte[])reader.GetValue(14);
return binaryData ;
}
我想返回binaryData,但是不能.
binaryData从Sql2008R2中读取fild varbinary(max).
varbinary归档的是图片或图像到db.
错误是:(局部变量)byte [] binaryData
ERRoR:
使用未分配的局部变量"binaryData"
i want return binaryData .but cant.
binaryData read fild varbinary(max) from Sql2008R2.
varbinary filed is picture or image to db.
error is :(local variable) byte[] binaryData
ERRoR:
use of unassigned local variable ''binaryData''
thanks.
推荐答案
byte[] binaryData = null;
而且,如果您不想调用代码来处理null
,请将其初始化为零长度的数组.
And if you don''t want calling code to handle a null
, initialize it to a zero length array.
byte[] binaryData = new byte[0];
发生编译器错误的原因是,如果您不输入if
块,则它是一个代码分支,其中局部变量保持未初始化状态(这会破坏C#规则,从而导致错误).
The reason for the compiler error is that if you don''t enter the if
-block, then it''s a code-branch where the local variable remains uninitialized (which breaks C# rules, and hence the error).
这篇关于请问什么是错误功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!