错误是什么(不是所有路径都返回一个值) [英] What is the problem error is (not all paths return a value)
本文介绍了错误是什么(不是所有路径都返回一个值)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
public Stream DownloadFile()
{
using (SqlConnection con = new SqlConnection("GAPDB"))
{
using (SqlCommand cmd = new SqlCommand("SELECT FileUpload FROM [FirmWareVersion]", con))
{
con.Open();
SqlDataReader reader = cmd.ExecuteReader();
if (reader.Read())
{
byte[] data = (byte[])reader["FileUpload"];
System.IO.MemoryStream ms = new System.IO.MemoryStream(data);
}
}
}
}
我尝试了什么:
首先我认为这是一个连接字符串但不是我需要一些帮助请
What I have tried:
first i thought it was an connection string but not that i need some help please
推荐答案
你的方法应该返回一个Stream
类型的变量,但是我无处可见 return 在你的代码中...
尝试这样的事情:
Your method should return a variable ofStream
type, but nowhere I can see a return in your code...
Try something like this:
public Stream DownloadFile()
{
using (SqlConnection con = new SqlConnection("GAPDB"))
{
using (SqlCommand cmd = new SqlCommand("SELECT FileUpload FROM [FirmWareVersion]", con))
{
con.Open();
SqlDataReader reader = cmd.ExecuteReader();
if (reader.Read())
{
byte[] data = (byte[])reader["FileUpload"];
System.IO.MemoryStream ms = new System.IO.MemoryStream(data);
return( ms ); // return it...
}
}
}
return( null ); // return null as sign of failure...
}
错误说不是所有路径都返回一个值。那么,为什么编译器认为你的代码需要返回一个值呢?因为你如何声明这个方法。你告诉编译器你的方法将返回一个Stream。但是你没有任何返回Stream的代码。
The error says that "not all paths return a value." So, why does the compiler think your code needs to return a value? Because of how you declared this method. You told the compiler that your method will be returning a Stream. But you do not have any code that returns a Stream.
这篇关于错误是什么(不是所有路径都返回一个值)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文