fileupload问题?
上传一个文件,同时将该文件的文件名,上传事件存入数据库!请问该怎么实现?数据库名:file_message 字段:f_name,f_time
我的代码如下:
protected void Button1_Click(object sender, EventArgs e)
{
string savePath=@"d:\";
if (FileUpload1.HasFile)
{
SqlConnection myConn = GetConnection();
myConn.Open();
string fileName = FileUpload1.FileName;
string sqlstr = "insert into file_message(f_name,f_time) value(,'"+fileName +"','"+DateTime .Now.ToLongDateString +"')";
SqlCommand myCmd = new SqlCommand(sqlstr ,myConn );
myCmd.ExecuteNonQuery();
myCmd.Dispose();
myConn.Close();
savePath += fileName;
FileUpload1.SaveAs(savePath);
Response.Write("<script>alert('上传成功!');</script>");
}
else
{
Response.Write("<script>alert('您没有选择上传文件!');</script>");
}
}