下面代码是显示图片:private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
string con=ConfigurationSettings.AppSettings["lib"];
SqlConnection myConnection=new SqlConnection(con); SqlDataAdapter myCommand=new SqlDataAdapter("select imagetit from news where id=(select max(id) from news)",myConnection); //从数据库中选择id号最大的图片标题名“imagetit”
DataSet news=new DataSet();
myCommand.Fill(news,"imagetit");
string imagename=news.Tables["imagetit"].Rows[0].ToString();
imageSmall.ImageUrl="upload/"+"small/"+imagename; //显示图片语句,图片保存位置..upload/small/图片 }
是何原因???
{
// 在此处放置用户代码以初始化页面
string con=ConfigurationSettings.AppSettings["lib"];
SqlConnection myConnection=new SqlConnection(con); SqlDataAdapter myCommand=new SqlDataAdapter("select imagetit from news where id=(select max(id) from news)",myConnection); //从数据库中选择id号最大的图片标题名“imagetit”
DataSet news=new DataSet();
myCommand.Fill(news,"imagetit");
string imagename=news.Tables["imagetit"].Rows[0].ToString();
imageSmall.ImageUrl="upload/"+"small/"+imagename; //显示图片语句,图片保存位置..upload/small/图片 }
是何原因???
好象没错
好象有点问题
你用 id IN (select max(id) from news)试试,我看了MS-SQL-SERVER数据库的书
好象没有看到什么ID=(SELECT .....)
如果在不行,你在upload前面加../试试看
我在查询分析器里实验过了,这个SQL语句没有错误,既可以用“=”也可以是“in”
图片保存位置..upload/small/图片
imageSmall.ImageUrl=Server.Mapath("upload/")+"small/"+imagename;
还有 你可以 把 "upload/"+"small/"+imagename; 打印出来看一看 是否正确
SqlDataAdapter myCommand=new SqlDataAdapter("select imagetit from news where id in (select max(id) from news)",myConnection);
DataSet news=new DataSet();
myCommand.Fill(news,"imagetit");
string imagename=news.Tables["imagetit"].Rows[0].ToString();
imageSmall.ImageUrl="upload/"+"small/"+imagename;
这个代码的结果是:用浏览器运行后不成功,查看它的源文件
路径居然是<img id="imageSmall" src="upload/small/System.Data.DataRow" border="0"...
不是图片名