C# 从数据库中读取图片的问题
代码死活读取不了图片SqlConnectiondef=newSqlConnection(System.Web.Configuration.WebConfiguration...
代码死活读取不了图片
SqlConnection def = new SqlConnection(System.Web.Configuration.WebConfigurationManager.ConnectionStrings["FlowerConnectionString"].ConnectionString.ToString()); def.Open(); SqlCommand sqlComGet = new SqlCommand(); //创建SqlCommand对象 sqlComGet.Connection = def; //用sqlCon初始化SqlCommand对象
sqlComGet.CommandText = "select ImagePath from peopleimage where name='" + Session["UserName"].ToString() + "'"; SqlDataReader sqlDr = sqlComGet.ExecuteReader(); //创建SqlDataReader对象
if (sqlDr.Read()) //帐号和密码正确 { Image1.ImageUrl = sqlDr.GetString(0); } 展开
SqlConnection def = new SqlConnection(System.Web.Configuration.WebConfigurationManager.ConnectionStrings["FlowerConnectionString"].ConnectionString.ToString()); def.Open(); SqlCommand sqlComGet = new SqlCommand(); //创建SqlCommand对象 sqlComGet.Connection = def; //用sqlCon初始化SqlCommand对象
sqlComGet.CommandText = "select ImagePath from peopleimage where name='" + Session["UserName"].ToString() + "'"; SqlDataReader sqlDr = sqlComGet.ExecuteReader(); //创建SqlDataReader对象
if (sqlDr.Read()) //帐号和密码正确 { Image1.ImageUrl = sqlDr.GetString(0); } 展开
展开全部
你那个imagepath倒底是路径,还是包含有完整的文件名的,如果没有文件名那就应该加上前面的imagename,另外,未做测试,但感觉imagepath中的\应该替换为/
追问
路径
追答
sqlComGet.CommandText = "select * from peopleimage where name='" + Session["UserName"].ToString() + "'";
SqlDataReader sqlDr = sqlComGet.ExecuteReader(); //创建SqlDataReader对象
if (sqlDr.Read())
{
Image1.ImageUrl = sqlDr["imagepath"].ToString().Replace("\\","/").Trim('/')+"/"+sqlDr["imagename"].ToString();
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询