Asp.net add data from a form to database RRS feed

  • Question

  • User-2094959909 posted
    Hello everyone i made a form (asp.net)with many textboxs to fill and the last one is a video ... my question is how can i save data of all inputs including input of video to my database and how can i get the data from my database to another form to show ??
    Please help me !!
    Ps: i use asp.net not mvc not core just simple
    Thursday, July 5, 2018 11:27 AM

All replies

  • User2053451246 posted

    There are millions of starter tutorials on these basic skills you are asking about.  Best place to start is the Learn tab at the top of this site.  Learn the basics, then ask a question when you are stuck at a specific point.


    Thursday, July 5, 2018 1:47 PM
  • User632428103 posted

    Hello all,

    @omar27 => make a simple app in the begining where you can add value locate in textbox and save these value into a database.

    After, when all will be ok, add an upload file to select a video file ...for to finish your problem read this article


    Thursday, July 5, 2018 2:24 PM
  • User283571144 posted

    Hi Omar27,

    According to your description, I suggest you could consider saving the video in  your server’s disc and saving the path of your video with other data in the database.

    This will avoid loading a lot of the data from SQL database to improve your web application's performance.

    More details, you could refer to below code demo:

    Upload page:

    It contains a textbox and upload control..

    <form id="form1" runat="server"  >
                <asp:Label ID="Label2" runat="server" Text="VideoName"></asp:Label><asp:TextBox ID="VideoName" runat="server"></asp:TextBox><br/>
                <asp:Label ID="Label3" runat="server" Text="File"></asp:Label><asp:FileUpload ID="FileUpload1" runat="server" />
                <br />
                      <asp:Button ID="Button1" runat="server" Text="Button"  OnClick="Button1_Click" />
                <asp:Label ID="Label1" runat="server" Text=""></asp:Label>
                <asp:LinkButton ID="LinkButton1" runat="server" PostBackUrl="~/ShowPage.aspx">go to showPage</asp:LinkButton>


    protected void Button1_Click(object sender, EventArgs e)
                HttpPostedFile file = FileUpload1.PostedFile;
                string name = "/File/" + Guid.NewGuid().ToString() + ".mp4";
                file.SaveAs(Server.MapPath( name));
                Label1.Text = name;
                string sql = "insert into Video (name,videopath) values(@name,@videoPath)";
                SqlParameter[] sqlParameters = new SqlParameter[] {
                    new SqlParameter("@name",System.Data.SqlDbType.Char,50){Value=VideoName.Text},
                    new SqlParameter("@videoPath",System.Data.SqlDbType.Char,100){Value=name}
                string connstr = "data source=localhost;initial catalog=bjhksj;integrated security=True";
                    using (SqlConnection con = new SqlConnection(connstr))
                        using (SqlCommand com = new SqlCommand(sql, con))

    Video Show page:


    <form id="form1" runat="server">
                 <asp:Label ID="Label2" runat="server" Text="VideoName"></asp:Label> :<asp:Label ID="Label1" runat="server" Text=""></asp:Label><br/>
                 <asp:Label ID="Label4" runat="server" Text="VideoPath"></asp:Label>:<asp:Label ID="Label3" runat="server" Text="File"></asp:Label>
                <video  controls="controls" id="myVideo"></video>
               $(function () {
                   $("#myVideo").attr("src", $("#Label3").text());


    protected void Page_Load(object sender, EventArgs e)
                SqlConnection con = new SqlConnection("data source=localhost;initial catalog=bjhksj;integrated security=True");
                string sql = "select top 1 * from Video";
                using (SqlCommand com = new SqlCommand(sql, con))
                    using (SqlDataReader reader = com.ExecuteReader(System.Data.CommandBehavior.CloseConnection))
                        if (reader.HasRows)
                          Label1.Text=  reader.GetString(2);
                            Label3.Text = reader.GetString(1);

    Best Regards,


    Sunday, July 8, 2018 10:49 AM