请问什么是错误功能 [英] Please what is the error function

查看:66
本文介绍了请问什么是错误功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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.

推荐答案

binaryData 初始化为null.

Initialize binaryData to null.

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).


您需要创建一个属性以返回二进制值...
您最好返回任何值...
You need to create a property to return a binary value...
It is more better for you to return any value...


这篇关于请问什么是错误功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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