客户端:
<INPUT id="myfile" style="Z-INDEX: 101; LEFT: 14px; POSITION: absolute; TOP: 13px" type="file" name="myfile" runat="server">服务器端:
if(this.myfile.PostedFile!=null)
{
                System.IO.Stream fs=this.myfile.PostedFile.InputStream;
                byte[] flob=new byte[fs.Length];
   int n= fs.Read(flob,0,(Int32)fs.Length);
dbconn.ConnectionString=Public.PuBDataBase.DBconnectiongstring;
dbconn.Open();
dbcmd.UpdateCommand.Connection=dbconn;
dbcmd.UpdateCommand.CommandText="update doc_table set a1=? where a0=2";
dbcmd.UpdateCommand.Parameters.Add("a1",System.Data.OleDb.OleDbType.Binary);
dbcmd.UpdateCommand.Parameters["a1"].Value=flob;
dbcmd.UpdateCommand.ExecuteNonQuery();
dbcmd.UpdateCommand.CommandText="commit";
                dbcmd.UpdateCommand.ExecuteNonQuery();
}
这就是写道数据库(oracle 8i a1 long raw子段)

解决方案 »

  1.   

    SQL SERVER数据库添加新记录的同时上传文件,我是使用TABLE中的关键字,如:ID作为上传文件名的。另外需要在IIS中添加一个虚拟目录,下面是部分代码:
    //添加新记录的同时上传attach file

    SqlDataAdapter myCommand1 = new SqlDataAdapter("SELECT MAX(id) AS maxid FROM sampleTable", myConnection);
            DataSet ds = new DataSet();
            myCommand1.Fill(ds, "sampleTable");
    foreach( DataRow app in ds.Tables["sampleTable"].Rows) { 
    Text1.Value =app["maxid"].ToString() ;
            }
            if (checkbox1.Checked ==true){
    //if File1.Value

    try{File1.PostedFile.SaveAs("E:\\upload\\"+Text1.Value+ ".pdf");
    Message.InnerHtml = "<b>File uploaded successful</b><br>";
    Message.Style["color"] = "blue";
                 }
                 catch (Exception exc) 
                 {
    Message.InnerHtml = "<b>Error in uploading file</b><br>";
    Message.Style["color"] = "red";
                 }      //更新table中新插入记录的字段[attachfile].即加入超级链接。
    String updateCmd = "UPDATE sampleTable SET attachfile = @attachfile where id = "+Text1.Value;
    SqlCommand myCommand2 = new SqlCommand(updateCmd, myConnection);
    myCommand2.Parameters.Add(new SqlParameter("@attachfile", SqlDbType.NVarChar, 50));
    myCommand2.Parameters["@attachfile"].Value = "/cattach/" + Text1.Value + ".pdf";
    myCommand2.Connection.Open();
    try 
    {
    myCommand2.ExecuteNonQuery();
    Message.InnerHtml = "<b>Record updated</b><br>";
    Message.Style["color"] = "blue";
    }
    catch (SqlException e)
    {
    Message.InnerHtml = "<b>ERROR: Could not update record, please ensure the fields are correctly filled out!</b>";
    Message.Style["color"] = "blue";
    }
    myCommand2.Connection.Close();
    BindGrid2();
            }