asp.net - How to Upload Video in database using C#.net in Visual studio 2008 -
i have below code upload video files database when upload video , click on upload button webpage go offline , data not store data base happening don't know.
my database table is
create table [dbo].[tblvideos]( [id] [int] identity(1,1) not null, [video_name] [varbinary](50) null, [name] [varchar](50) null, [contenttype] [varbinary](50) null, [data] [varbinary](max) null ) on [primary]
my aspx code
<table style="margin-left:150px; height:546px"> <tr class="tr"> <td colspan="3"> <asp:label id="label1" runat="server" font-size="15pt" forecolor="#0099ff" text="add new video"></asp:label> <br /> <asp:label id="label2" runat="server" font-names="ms reference sans serif" font-size="7pt" text="make sure video in mp4 format"></asp:label> </td> </tr> <tr class="tr"> <td class="style1"> video name :</td> <td><asp:textbox id="txtideoname" height="24px" width="270px" runat="server"></asp:textbox></td> <td> </td> </tr> <tr class="tr"> <td class="style1">video type :</td> <td><asp:textbox id="txtvideotype" height="24px" width="270px" runat="server"></asp:textbox></td> <td> </td> </tr> <tr class="tr"> <td class="style1">video:</td> <td> <asp:fileupload id="fileupload1" runat="server" /></td> <td> </td> </tr> <tr class="tr"> <td> </td> <td><asp:button id="btnupload" runat="server" text="upload" width="132px" height="34px" backcolor="red" borderstyle="none" font-bold="true" forecolor="white" onclick="btnupload_click"/><br /> <asp:label id="lblmsg" runat="server"/></td> <td> </td> </tr> <tr class="tr"> <td> </td> <td> </td> <td> </td> </tr> </table> c# code using (binaryreader br = new binaryreader(fileupload1.postedfile.inputstream)) { byte[] bytes = br.readbytes((int)fileupload1.postedfile.inputstream.length); string strconnstring = configurationmanager.connectionstrings["con1"].connectionstring; using (sqlconnection con = new sqlconnection(strconnstring)) { using (sqlcommand cmd = new sqlcommand()) { cmd.commandtext = "insert tblvideos(video_name,name, contenttype, data) values (@video_name,@name, @contenttype, @data)"; cmd.parameters.addwithvalue("@video_name", txtideoname.text); 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(); } } }
one potential problem both video_name
, contenttype
being stored varbinary
, , don't seem cast in sql. have tried changed them varchar
?
Comments
Post a Comment