我有一个数据库需要向其中的一个表里的一个 字段写入图片,请问该怎么做?
最好能提供asp.net(使用vb.net)源码和解释,因为我是一个菜鸟!!!

解决方案 »

  1.   

    向SQL Server数据库添加图片和文字
    http://dotnet.aspx.cc/ShowDetail.aspx?id=J9UBRVER-L3VB-49M3-GOU1-Z6C2PVR6FZ3K
      

  2.   

    http://community.csdn.net/Expert/topic/3690/3690534.xml?temp=.5795404
    http://community.csdn.net/Expert/topic/3713/3713493.xml?temp=.1171076
      

  3.   

    一个居于Access的上传图片,用C#写的,VB.net大同小异
    using System;
    using System.Collections;
    using System.ComponentModel;
    using System.Data;
    using System.Data.OleDb;
    using System.Drawing;
    using System.Web;
    using System.Web.SessionState;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.HtmlControls;namespace AccessUpload
    {
    /// <summary>
    /// WebForm1 的摘要说明。
    /// </summary>
    public class WebForm1 : System.Web.UI.Page
    {
    protected System.Web.UI.WebControls.Button but;
    protected System.Web.UI.HtmlControls.HtmlInputFile File;

    private void Page_Load(object sender, System.EventArgs e)
    {
    // 在此处放置用户代码以初始化页面
    } #region Web 窗体设计器生成的代码
    override protected void OnInit(EventArgs e)
    {
    //
    // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
    //
    InitializeComponent();
    base.OnInit(e);
    }

    /// <summary>
    /// 设计器支持所需的方法 - 不要使用代码编辑器修改
    /// 此方法的内容。
    /// </summary>
    private void InitializeComponent()
    {    
    this.but.Click += new System.EventHandler(this.but_Click);
    this.show.Click += new System.EventHandler(this.show_Click);
    this.Load += new System.EventHandler(this.Page_Load); }
    #endregion private void but_Click(object sender, System.EventArgs e)
    {
    if(File.PostedFile!=null && File.PostedFile.ContentLength!=0)
    {
    string filename = File.PostedFile.FileName.Substring(File.PostedFile.FileName.LastIndexOf("\\")+1);   //文件名称
    string filetype = File.PostedFile.ContentType;  //文件类型
    int filesize = File.PostedFile.ContentLength;  //文件大小
    byte[] filedata = new byte[filesize];      //文件内容
    File.PostedFile.InputStream.Read(filedata,0,filesize);
    string conStr = "Provider = Microsoft.Jet.OLEDB.4.0;Data Source =" + Server.MapPath("Data/db1.mdb");
    OleDbConnection con = new OleDbConnection(conStr);

    OleDbCommand cmd = con.CreateCommand();
    cmd.CommandText = "Insert into photo (filename,filetype,filesize,filedata) Values (@filename,@filetype,@filesize ,@filedata )";
    cmd.Parameters.Add("@filename",OleDbType.VarChar,50).Value = filename;
    cmd.Parameters.Add("@filetype",OleDbType.VarChar,50).Value = filetype;
    cmd.Parameters.Add("@filesize",OleDbType.BigInt,8).Value = filesize;
    cmd.Parameters.Add("@filedata",OleDbType.Binary,filesize).Value = filedata;
    con.Open();
    try
    {
    cmd.ExecuteNonQuery();
    }
    catch(OleDbException exp){Response.Write(exp.Message);}
    con.Close();
    //上传成功

    }
    else
    {
    Response.Write("请选择文件");
    } } }
    }
      

  4.   

    //获得图象并把图象转换为byte[] 
    HttpPostedFile upPhoto=UpPhoto.PostedFile; 
    int upPhotoLength=upPhoto.ContentLength; 
    byte[] PhotoArray=new Byte[upPhotoLength]; 
    Stream PhotoStream=upPhoto.InputStream; 
    PhotoStream.Read(PhotoArray,0,upPhotoLength); //连接数据库 
    SqlConnection conn=new SqlConnection(); 
    conn.ConnectionString="Data Source=localhost;Database=test;User Id=sa;Pwd=sa"; SqlCommand cmd=new SqlCommand("UpdateImage",conn); 
     
    string strSql="Insert into test(FImage) values(@FImage)"; 
    SqlCommand cmd=new SqlCommand(strSql,conn); 
    cmd.Parameters.Add("@FImage",SqlDbType.Image); 
    cmd.Parameters["@FImage"].Value=PhotoArray; conn.Open(); 
    cmd.ExecuteNonQuery(); 
    conn.Close(); 
      

  5.   

    向SQL Server数据库添加图片
    http://dotnet.aspx.cc/ShowDetail.aspx?id=2A5DD7C6-A45A-48AB-A2E8-342A29F17506
      

  6.   

    向SQL Server数据库添加大图片和缩略图
    http://www.cnblogs.com/rippleyong/archive/2004/08/10/31977.aspx
      

  7.   

    你们都用c#,把我看得头都大了,哎!!!难道Vb.net落伍了???
      

  8.   

    对了,我要的是access数据库,要求把用户照片上传并写到数据库,然后再通过数据库搜索将起个人资料显示出来,我看了一下,你们给的 都有些出入,如果谁给完整代码,立即给分!!!
      

  9.   

    下面的问题,请高手帮助解决!!!“/WebApplication1”应用程序中的服务器错误。
    --------------------------------------------------------------------------------字段太小而不能接受所要添加的数据的数量。试着插入或粘贴较少的数据。 
    说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.Data.OleDb.OleDbException: 字段太小而不能接受所要添加的数据的数量。试着插入或粘贴较少的数据。源错误: 
    行 52:         cmd.Parameters(0).Value = bindata
    行 53:         conn.Open()
    行 54:         cmd.ExecuteNonQuery()
    行 55:         conn.Close()
    行 56: 
     源文件: F:\Inetpub\wwwroot\WebApplication1\SaveImage.aspx.vb    行: 54 堆栈跟踪: 
    [OleDbException (0x80040e57): 字段太小而不能接受所要添加的数据的数量。试着插入或粘贴较少的数据。]
       System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(Int32 hr) +43
       System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult) +174
       System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult) +92
       System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult) +65
       System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method) +112
       System.Data.OleDb.OleDbCommand.ExecuteNonQuery() +67
       WebApplication1.SaveImage.Button1_Click(Object sender, EventArgs e) in F:\Inetpub\wwwroot\WebApplication1\SaveImage.aspx.vb:54
       System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108
       System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +57
       System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +18
       System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
       System.Web.UI.Page.ProcessRequestMain() +1277 
    --------------------------------------------------------------------------------
    版本信息: Microsoft .NET Framework 版本:1.1.4322.573; ASP.NET 版本:1.1.4322.573
      

  10.   

    请给予帮助,如何想access数据库里写入大图片文件,要求喊有上传的代码和显示的代码,谢谢!!!
      

  11.   

    使用数据类型System.Data.OleDb.OleDbType.Binary