问题是这样的:在WINFORM中通过一个BUTTON选择磁盘上的一张图片,然后把图片路径存到数据库中的表中,也就是对应的字段是nchar,不是image
查询图片,通过在TEXTBOX中输入图片对应的ID,在PICTUREBOX中显示该图片

解决方案 »

  1.   

    这是在web页面的上传图片,你看看,或许对你有帮助
    上传控件protected void btnUpLoad_Click(object sender, Infragistics.WebUI.WebDataInput.ButtonEventArgs e)
        {
            string FullFileName = this.FileUpload1.PostedFile.FileName;
            string FileName = FullFileName.Substring(FullFileName.LastIndexOf("\\")+1);//从这个字符以后取出,所以加1
            this.FileUpload1.PostedFile.SaveAs(Server.MapPath("up" + "\\"+FileName));
        }
      

  2.   

    private void bn_upload_Click(object sender, System.EventArgs e)
    {   
    string File =pic.PostedFile.FileName;          //获取客户端文件的路径和文件名和扩展名
    string FilePath=Server.MapPath("\\book\\upload").ToString();  //保存文件路径
    string FileName=Path.GetFileName(File);          //获取文件的名字和扩展名
                string FType=pic.PostedFile.ContentType;          //文件类型
    if(!pic.PostedFile.FileName.Equals(""))           //选中文件
    {
    try
    {
    if(!Directory.Exists(FilePath))  //是否存在该目录
    {
                            Directory.CreateDirectory(FilePath);  //建立目录
    }
    if(FType.Substring(0,5)!="image")  //上传的是否图片类型
    {
    this.la_new.Text="你上传的不是图片!";
    return;
    }
    pic.PostedFile.SaveAs(FilePath+"\\"+FileName);  //保存图片到指定地址
    img.ImageUrl="upload\\"+FileName;  //显示图片地址
    ViewState["PostFileName"]=FileName;                      //通过VIEWSTATE记录图片的名字
    }
    catch(Exception ex)
    {
    this.la_new.Text="上传文件错误!";
    }
    }


    }//显示Image1.ImageUrl=数据库中的记录
      

  3.   

    private void Page_Load(object sender, System.EventArgs e)
    {
    SqlConnection myDSN = new SqlConnection( ConfigurationSettings.AppSettings["strConn"] );
    myDSN.Open();
    string SqlText = "SELECT FileName, FileExt, imageintr From UpFile Where ID="+ Request.QueryString["id"];
    Trace.Write(SqlText);
    SqlCommand MyCommand = new SqlCommand (SqlText, myDSN);
    SqlDataReader dr =MyCommand.ExecuteReader();
    if(dr.Read())
    {
    Response.ContentType = (dr["FileExt"].ToString());
    Response.BinaryWrite((byte[])dr["imageintr"]);
    Response.Flush();
    }
    myDSN.Close();
    }
    //显示图片
    Image1.Visible = true;
    Image1.ImageUrl = "Fileview.aspx?id="+Request.QueryString["UpID"];
      

  4.   

    简单点:
    1:用openfiledialog1.filename得到文件名
    2:用insert into [表名](image) values (openfiledialog1.filename);
    插入到数据库中,在数据库中,查看,是否成功,
    3: 用select image from [表名] where id="X";
    得到文本,再用它做为图片的地址。
      

  5.   

       存 ; 把图片上传 ,在数据库中保存其相对路径,
       取 :跟句id 查到那一条记录 ,读取它的图片路径 ,给img的url就可以啊 ,