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!";
}
}
答案 0 :(得分:0)
你在哪里提到你的SQL服务器连接字符串?
SqlConnection con = new SqlConnection(YOUR_CONNECTION_STRING_HERE);
con.Open();
然后执行您的查询。