我正在尝试将文件名和文件路径保存在数据库中。但无法保存它:(。数据库连接工作正常,但我不知道是什么问题
con.Open();
string fileExt = System.IO.Path.GetExtension(FileUpload1.FileName);
SqlCommand cmd = new SqlCommand("insertintoTbl_Videos(VideoName,VideoPath)values(@VideoName,@VideoPath)",con);
if (fileExt == ".avi")
{
try
{
cmd.Parameters.AddWithValue("@VideoName", "video/"+FileUpload1.FileName);
cmd.Parameters.AddWithValue("@VideoPath", "video/" +FileUpload1.FileName);
FileUpload1.SaveAs(Server.MapPath("~/video/" + FileUpload1.FileName));
Literal1.Text = "upload";
cmd.ExecuteNonQuery();
}
catch (Exception ex)
{
Label1.Text = "ERROR: " + ex.Message.ToString();
}
}
else
{
Label1.Text = "Only .avi files allowed!";
}
}
}