Click here to Skip to main content
15,895,011 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i used the following code for uploading and inserting video into mysql database but does not run .. can anyone help me ??

C#
public class FileUploadController : Controller
    {
        //
        // GET: /FileUpload/

        string strcon = "server=ASMAA-PC;database=SignLanguage;integrated security=true";
        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult FileUpload(HttpPostedFileBase FileUpload1)
        {
            using (BinaryReader br = new BinaryReader(FileUpload1.PostedFile.InputStream))
            {
                byte[] bytes = br.ReadBytes((int)FileUpload1.PostedFile.InputStream.Length);
                // string strConnString = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;

                using (SqlConnection con = new SqlConnection(strcon))
                {
                    using (SqlCommand cmd = new SqlCommand())
                    {
                        cmd.CommandText = "insert into tblFiles(Video_name, ContentType, Data) values (@Name, @ContentType, @Data)";
                        cmd.Parameters.AddWithValue("@Name", Path.GetFileName(FileUpload1.PostedFile.FileName));
                        cmd.Parameters.AddWithValue("@ContentType", "video/mp4");
                        cmd.Parameters.AddWithValue("@Data", bytes);
                        cmd.Connection = con;
                        con.Open();
                        cmd.ExecuteNonQuery();
                        con.Close();

                    }
                }
            }
            return View();
        }
Posted

1 solution

cmd.Parameters.AddWithValue("@Name", Path.GetFileName(FileUpload1.PostedFile.FileName));
You are just storing the name of the file here. You need to convert the image into bytes and store it in the database.

E.g. http://blog.sqlauthority.com/2009/07/13/sql-server-blob-pointer-to-image-image-in-database-filestream-storage/
 
Share this answer
 
Comments
Member 9702410 9-Jun-13 14:47pm    
i already used the following code http://www.codeproject.com/Articles/21480/Video-Uploader-Control-for-SQL-Server , but i want to use this with MVC3 ASP.NET

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900