Csharp/C#教程:如何使用c#将video保存到数据库?分享


如何使用c#将video保存到数据库?

我有想要将video存储到数据库并在网格中显示从数据库下载的场景,我将通过fileupload控件上传video,它应该是sql server2008数据库,这是c#和asp.net的最佳方式?

它有很多链接。 看看这个。

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

https://forums.asp.net/t/1104451.aspx/1?How+to+retrieve+video+file+from+s++server+database https://www.saurabhdeveloper.com/techtips_details.php?tipsid = 15 https://forums.asp.net/p/1533758/3719583.aspx https://forums.asp.net/t/1045855.aspx/2/10 https://forums.asp.net/t/ 1511588.aspx / 1 https://www.dotnetspider.com/forum/274821-Play-video-file-asp-net-page.aspx https://blogs.ugidotnet.org/kfra/archive/2006/10/ 04 / 50003.aspx https://www.dotnetspider.com/resources/16239-code-for-video-upload.aspx

https://www.c-sharpcorner.com/Forums/Thread/88899/ https://www.asp.net/webmatrix/tutorials/10-working-with-video

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

试试这个代码

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"; } } 

你说它“应该”是SQL Server 2008,但它必须是吗?

如果没有,SQL Server 2012提供了用于在SQL Server中存储大型文件的文件表 。 它实际上将数据存储在文件系统上,但是您不必编写任何代码来管理实际文件。

如果它确实需要是SQL Server 2008,那么您有以下选项:

1)使用varbinary(MAX)列类型的FileStream – 此方法可能存在性能问题。 我个人不会以这种方式存储video。

2)将文件放在文件系统上(在磁盘上),只将文件路径/文件名存储在DB中。 然后编写代码来管理文件系统上的CRUD操作。

它将帮助您…请参阅以下链接https://www.codeproject.com/Articles/308552/Upload-and-Download-Files-to-SQL-Servers-in-ASP-Ne

上述就是C#学习教程:如何使用c#将video保存到数据库?分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)!

本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

ctvol管理联系方式QQ:251552304

本文章地址:https://www.ctvol.com/cdevelopment/1014442.html

(0)
上一篇 2021年12月30日
下一篇 2021年12月30日

精彩推荐