Asp.net 如何在数据库中存储图像并检索它们

Asp.net 如何在数据库中存储图像并检索它们,asp.net,database,file-upload,image-uploading,Asp.net,Database,File Upload,Image Uploading,我从互联网上下载了很多代码,但没有一个能正常工作,所以请大家拿出一个真正的解决方案。。。。 请帮帮我 <%@ Import Namespace = "System.Data" %> <%@ Import Namespace = "System.Data.SqlClient" %> <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="t

我从互联网上下载了很多代码,但没有一个能正常工作,所以请大家拿出一个真正的解决方案。。。。 请帮帮我

<%@ Import Namespace = "System.Data" %>
<%@ Import Namespace = "System.Data.SqlClient" %>
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <link href="../css/fileuploader.css" rel="stylesheet" type="text/css">
    <style>
        body {font-size:10px; font-family:arial, sans-serif; width:700px; margin:100px auto;}
        td{
        font-family:Verdana; 
        font-size:1;

}
    </style>
</head>
<body onload="document.getElementById('myapp').focus()">



    <script src="../js/fileuploader.js" type="text/javascript"></script>
    <script>
        function createUploader(){
            var uploader = new qq.FileUploader({
                element: document.getElementById('fupld'),
                action: 'fup.aspx',
                params: {
                            'phones': document.getElementById('hdn').value,
                            'appname':document.getElementById('myapp').value

                    }
                ,

                debug: true
            });
        }

        // in your app create uploader as soon as the DOM is ready
        // don't wait for the window to load
        //window.onload = createUploader;
    </script>

    <b>Enter Application Name</b> : <input type="text" id="myapp" onBlur="document.getElementById('phonediv').style.display='block'">
    <br/><br/><br/><br/><br/>
    <div id="phonediv" style="border:1px solid;border-radius:5px;-moz-border-radius:5px;">
    <%
        Dim builder As New StringBuilder
        Dim RetRes As String
        Dim con As New SqlConnection
        Dim cmd As New SqlCommand
        Try
         con.ConnectionString = ConfigurationManager.ConnectionStrings("sqlsds").ConnectionString  
         con.Open()
         cmd.Connection = con
         cmd.CommandText = "select distinct user_friendly_device_model,browser_returned_device_model from dbo.DeviceServiceMap"
         Dim lrd As SqlDataReader = cmd.ExecuteReader()
         Dim i As Integer
%>
<table border="0">
<tr>
<%
    While lrd.Read()
         i = i + 1    
    %>

        <td><%Response.Write(lrd.getValue(0))%> </td><td><input type=checkbox name='cb' value='<%Response.Write(lrd.getValue(1))%>' style='vertical-align:middle'> </td>
    <%  
         if i=4
    %>
    </tr><tr>
    <%
         i = 0
        End If
    End While
%>
</tr></table>
<%
        Catch ex As Exception

        Finally
         con.Close()
    End Try

%>

<br/>
<input type="Button" value="Next ..." onClick="a()" />
</div>
<input type="hidden" name="h" id="hdn">
</br>
<div id="fupld">

    </div>
</body>
<script language="javascript">
function a()
{
    if(document.getElementById('myapp').value.length==0)
        {
            alert("Enter Application Name Please")
            document.getElementById('myapp').focus()
            return false
        }



    var checkboxes = document.getElementsByName('cb');
      var checkboxesChecked="" ;
      // loop over them all
      for (var i=0; i<checkboxes.length; i++) 
      {
         // And stick the checked ones onto an array...
         if (checkboxes[i].checked) 
         {
            checkboxesChecked+=checkboxes[i].value+",";
         }
      }

   if(checkboxesChecked.length==0)
       {


           alert("Select At least one Model ...")
       checkboxes[0].focus()
       return false
      }
    document.getElementById('hdn').value= checkboxesChecked.substring(0,checkboxesChecked.length - 1)


        var letterNumber = /^[0-9a-zA-Z]+$/;
         if(document.getElementById('myapp').value.match(letterNumber)) 
          {
          createUploader()
           return true;
          }
        else
          { 
           alert("Enter only numbers and letters"); 
           document.getElementById('myapp').value=""
           document.getElementById('myapp').focus()
           return false
          }




//  document.getElementById('fupld').style.display='block'

}
</script>
</html>
fup.aspx

<%
 Dim apnm As String

 Dim phonelst As String

 apnm = Request.QueryString("appname")
 phonelst = Request.QueryString("phones")
 Dim fileName As String = context.Request.Headers("X-File-Name")



 Dim length As Integer = context.Request.ContentLength
 Dim documentBytes = New Byte(length - 1) {}
 context.Request.InputStream.Read(documentBytes, 0, length)

 Dim oFileStream As System.IO.FileStream
 oFileStream = New System.IO.FileStream(Server.MapPath("./apps/"& fileName), System.IO.FileMode.Create)
 oFileStream.Write(documentBytes, 0, documentBytes.Length)
 oFileStream.Close()

 Dim pnm() As String  
 pnm=phonelst.split(",")

 Dim i As Integer  
 for i= 0 to pnm.length - 1   


         Dim connection As  SqlConnection
            Dim cmd As  SqlCommand 
            Dim connectionString As String
            connectionString = ConfigurationManager.ConnectionStrings("sqlsds").ConnectionString      
            connection = New SqlConnection(connectionString)   

            cmd = New SqlCommand("dbo.spUpdatePhoneData", connection)
            cmd.CommandType = CommandType.StoredProcedure   
            cmd.Parameters.AddWithValue("@p_model",pnm(i))
            cmd.Parameters.AddWithValue("@p_apkname",apnm)
            cmd.Parameters.AddWithValue("@p_apkfile",fileName)


            Try

              connection.Open()
              cmd.ExecuteNonQuery()
            Catch ex As Exception
                Response.Write(ex.Message)
            Finally
             connection.Close()
            End Try
 Next i
 Response.Write("{success: true}")
%>

1.不要超过2。将图像存储在服务器上的文件夹中,并将路径保存在db中,检索时直接从db获取路径并将其传递到src tag1中。是的,好的,抱歉…:P 2.cn u gve给我一个示例发布代码这是使用fineuploader