【发布时间】:2021-04-15 19:10:18
【问题描述】:
我正在尝试将 ASP.NET 中的数据插入 SQL Server 并将其从 SQL Server 检索回 ASP.NET。
插入部分已完成,但我在检索数据时遇到问题。我正在使用此代码,但抛出错误:
SqlConnection con = new SqlConnection(myconnstrng);
con.Open();
SqlCommand cmd = new SqlCommand("selection", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@id", parameter);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet dsa = new DataSet();
da.Fill(dsa);
if (dsa.Tables[0].Rows.Count > 0)
{
MemoryStream ms = new MemoryStream((byte[])dsa.Tables[0].Rows[0]["Data"]);
string strBase64 = Convert.ToBase64String(ms);
ImageButton2.ImageUrl = "data:Image/png;base64," + strBase64;
}
我得到的错误是:
无法从“System.IO.MemoryStream”转换为“byte[]”
我是编程新手,如果有人可以帮助我解决这个问题。
谢谢大家!
【问题讨论】:
标签: c# asp.net sql-server