繁体   English   中英

fileupload值未保存在数据库中

[英]fileupload value is not saving in database

    SqlConnection con = new SqlConnection();
    SqlCommand cmd = new SqlCommand("insert into Tbl_Videos(VideoName,VideoPath)values(@VideoName,@VideoPath)");

    string fileExt = System.IO.Path.GetExtension(FileUpload1.FileName);

    if (fileExt == ".avi")
    {
        try
        {
            FileUpload1.SaveAs(Server.MapPath("~/video/" +FileUpload1.FileName));
            Label1.Text = "File name: " +
            FileUpload1.PostedFile.FileName + "<br>" +
            FileUpload1.PostedFile.ContentLength + " kb<br>" +"Content type: "+FileUpload1.PostedFile.ContentType;
           cmd.Parameters.AddWithValue("@VideoName",FileUpload1.FileName);
            cmd.Parameters.AddWithValue("@VideoPath", FileUpload1.FileName);
            cmd.ExecuteNonQuery();
        }
        catch (Exception ex)
        {
            Label1.Text = "ERROR: " + ex.Message.ToString();
        }
    }
    else
    {
        Label1.Text = "Only .avi files allowed!";
    }

}

您在哪里提到您的SQL Server连接字符串?

SqlConnection con = new SqlConnection(YOUR_CONNECTION_STRING_HERE); 
con.Open();

然后执行查询。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM