?????????????????ν??????????????SQL Server??????С?

????????????У??????varbinary(MAX)?洢??

?????????????MVC3????????????????????????????

????View??

@{
    ViewBag.Title = "UpLoadImg";
}
@using (Html.BeginForm("Create"?? "UpLoadImg"?? FormMethod.Post?? new { enctype = "multipart/form-data" }))
{
    <h2>
        UpLoadImg</h2>
    <div id="mainform">
        <div>
            <input type="file" id="UpLoadFile" name="UpLoadFile" />
            <input id="btnUpLoad" type="submit" value="???" />
        </div>
        <div>
        </div>
    </div>
}

????Controller???Action??

public ActionResult Create()
        {
            string filename = string.Empty;
            string filetype=string.Empty;
            byte[]  filecontext=null;
            HttpPostedFileBase filebase = Request.Files["UpLoadFile"];
            if (filebase.ContentLength > 0)
            {
                Stream stream = filebase.InputStream;
                byte[] by = new byte[filebase.ContentLength];
                int i = stream.Read(by??0??filebase.ContentLength);
                stream.Close();
                string[] arrs = filebase.FileName.Split('\');
                if (arrs.Length > 0)
                {
                    filename = arrs[arrs.Length - 1];
                }
                else
                {
                    filename = filebase.FileName;
                }
                filetype=filebase.ContentType;
                filecontext=by;
            }//?????????????????????????????????????????????????????????
            int count = 0;
            #region ????????
            try
            {
                string ImageStore = System.Configuration.ConfigurationManager.AppSettings["ConnectionStrImageStore"].ToString().Trim();
                string sqlStr = string.Empty;
                sqlStr = @"INSERT INTO [Images] ([filename]??[filetype]??[filecontext]??[uploadtime])
                    VALUES(@filename??@filetype??@filecontext??@uploadtime)";
                SqlConnection connection = new SqlConnection(ImageStore);
                SqlCommand command = new SqlCommand(sqlStr?? connection);
                command.Parameters.AddWithValue("@filename"??filename);
                command.Parameters.AddWithValue("@filetype"??filetype);
                command.Parameters.AddWithValue("@filecontext"??filecontext);
                command.Parameters.AddWithValue("@uploadtime"??DateTime.Now);
                command.Connection.Open();
                count=command.ExecuteNonQuery();
                command.Connection.Close();
            }
            catch
            {
              
            }
            #endregion

            if (count > 0)
            {
                return RedirectToAction("UpLoadImg");
            }
            else
            {
                return RedirectToAction("Index");
            }
        }