C#并非所有路径都返回值
当我将鼠标放在下载文件上时,它会显示(并非所有路径都返回值)。我需要做什么来解决这个问题C#并非所有路径都返回值,c#,C#,当我将鼠标放在下载文件上时,它会显示(并非所有路径都返回值)。我需要做什么来解决这个问题 public Stream DownloadFile() { using (SqlConnection con = new SqlConnection("GAPDB")) { using (SqlCommand cmd = new SqlCommand("SELECT FileUpload FROM [FirmWareVersion]", con)) {
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);
}
}
}
}
您需要返回
流
,因为您的方法将流
定义为返回类型:
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 null;
}
或者,如果不需要从方法返回,您可以将方法标记为
无效
。您需要返回流
,因为您的方法将流
定义为返回类型:
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 null;
}
或者,如果不需要从方法返回,您可以将方法标记为
void
。使用return something或null添加else条件编译器错误非常明显:甚至不是所有路径都返回值,也不是单个路径返回值!因此,在if块中添加一个返回ms
和可能的返回null方法结尾处的代码>。定义一个返回流的函数。但是在函数中,您不会返回任何东西,如果返回某物或null
则会返回其他条件。编译器的错误非常明显:甚至不是所有路径都返回值,也不是单个路径返回值!因此,在if块中添加一个返回ms
和可能的返回null方法结尾处的代码>。定义一个返回流的函数。但在函数中,您不返回任何内容