using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.IO;public partial class userinfo_ShowPhoto : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
       if(!Page.IsPostBack) 
       { 
SqlConnection conn=new SqlConnection(); 
conn.ConnectionString="Data Source=localhost;Database=yanlei;User Id=sa;Pwd=123";
conn.Open();
string strSql = "select * from photo where id=2";//这里假设获取id为2的图片 
SqlCommand cmd = new SqlCommand("strSql",conn);
SqlDataReader reader = cmd.ExecuteReader();  
reader.Read();
Response.ContentType="application/octet-stream";
Response.BinaryWrite((Byte[])reader["photo"]); 
Response.End();
reader.Close();
conn.Close();

    }
}错误信息:未能找到存储过程 'strSql'。

解决方案 »

  1.   

    SqlCommand cmd = new SqlCommand(strSql,conn); 
    cmd.CommandType = CommmandType.Text;
      

  2.   

    strSql 把它的引号去掉就行了,CommmandType.Text 这个是默认的,不用指定
      

  3.   

    SqlCommand cmd = new SqlCommand(strSql,conn); 
      

  4.   


    我改成这样后 !没有错误信息提示!可是 对不出来图片啊 !
    private void Page_Load(object sender, System.EventArgs e) 

    if(!Page.IsPostBack) 

    SqlConnection conn=new SqlConnection() 
    conn.ConnectionString="Data Source=localhost;Database=yanlei;User Id=sa;Pwd=123"; string strSql="select * from test where id=2";//这里假设获取id为2的图片 
    SqlCommand cmd=new SqlCommand() 
    reader.Read(); 
    Response.ContentType="application/octet-stream"; 
    Response.BinaryWrite((Byte[])reader["photo"]); 
    Response.End(); 
    reader.Close(); 

      

  5.   

    SqlCommand cmd = new SqlCommand("strSql",conn); 
    ==
    SqlCommand cmd = new SqlCommand(strSql,conn);