Sqlserver
 sql >> Cơ Sở Dữ Liệu >  >> RDS >> Sqlserver

Làm cách nào để lưu video vào cơ sở dữ liệu bằng c #?

Có rất nhiều liên kết cho nó. Kiểm tra cái này.

http://weblogs.asp.net/hajan/archive/2010/06/21/save-and-display-youtube-video-links-on-asp-net-website.aspx

http ://forums.asp.net/t/1104451.aspx/1? Cách + truy xuất + video + tệp + từ + sql + máy chủ + cơ sở dữ liệu http://www.saurabhdeveloper.com/techtips_details.php?tipsid=15 http://forums.asp.net/p/1533758/3719583.aspx http://forums.asp.net/t/1045855.aspx/2 / 10 http://forums.asp.net/t/1511588.aspx/1 http://www.dotnetspider.com /forum/274821-Play-video-file-asp-net-page.aspx http://blogs.ugidotnet.org/kfra/archive /2006/10/04/50003.aspx http://www.dotnetspider.com/resources/16239 -code-for-video-upload.aspx

http://www.c-sharpcorner.com/Forums/Thread/88899/ http://www.asp.net/webmatrix/tutorials/10 -làm việc với video

http://www.c-sharpcorner.com/Forums/Thread/88899/

Hãy thử mã này

 byte[] buffer;
//this is the array of bytes which will hold the data (file)

SqlConnection connection;
protected void ButtonUpload_Click(object sender, EventArgs e)
{
    //check the file

    if (FileUpload1.HasFile && FileUpload1.PostedFile != null 
        && FileUpload1.PostedFile.FileName != "")
    {
        HttpPostedFile file = FileUpload1.PostedFile;
        //retrieve the HttpPostedFile object

        buffer = new byte[file.ContentLength];
        int bytesReaded = file.InputStream.Read(buffer, 0, 
                          FileUpload1.PostedFile.ContentLength);

        if (bytesReaded > 0)
        {
            try
            {
                string connectionString = 
                  ConfigurationManager.ConnectionStrings[
                  "uploadConnectionString"].ConnectionString;
                connection = new SqlConnection(connectionString);
                SqlCommand cmd = new SqlCommand
                ("INSERT INTO Videos (Video, Video_Name, Video_Size)" + 
                 " VALUES (@video, @videoName, @videoSize)", connection);
                cmd.Parameters.Add("@video", 
                    SqlDbType.VarBinary, buffer.Length).Value = buffer;
                cmd.Parameters.Add("@videoName", 
                    SqlDbType.NVarChar).Value = FileUpload1.FileName;
                cmd.Parameters.Add("@videoSize", 
                    SqlDbType.BigInt).Value = file.ContentLength;
                using (connection)
                {
                    connection.Open();
                    int i = cmd.ExecuteNonQuery();
                    Label1.Text = "uploaded, " + i.ToString() + " rows affected";
                }
            }
            catch (Exception ex)
            {
                Label1.Text = ex.Message.ToString();
            }
        }

    }
    else
    {
        Label1.Text = "Choose a valid video file";
    }
}


  1. Database
  2.   
  3. Mysql
  4.   
  5. Oracle
  6.   
  7. Sqlserver
  8.   
  9. PostgreSQL
  10.   
  11. Access
  12.   
  13. SQLite
  14.   
  15. MariaDB
  1. Cách chuyển Loại bảng do người dùng xác định làm tham số có thủ tục được lưu trữ trong C #

  2. Cách thực hiện đánh dấu kết quả từ truy vấn toàn văn bản của SQL Server

  3. Ngăn chặn việc chèn các phạm vi ngày chồng chéo bằng cách sử dụng trình kích hoạt SQL

  4. Làm thế nào để buộc bộ thu gom rác dòng hoàn thành công việc của mình với mức độ ưu tiên cao nhất?

  5. Cách sử dụng API SSIS để đọc một gói và xác định chuỗi nhiệm vụ từ mã (PrecedenceConstraints)