| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 702 人关注过本帖
标题:fileupload问题?
只看楼主 加入收藏
yangxincheng
Rank: 1
等 级:新手上路
帖 子:27
专家分:0
注 册:2008-10-22
收藏
 问题点数:0 回复次数:1 
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>");
}


}
搜索更多相关主题的帖子: fileupload 
2008-12-11 11:03
叶飘
Rank: 1
等 级:新手上路
帖 子:37
专家分:0
注 册:2008-3-18
收藏
得分:0 
这样不是可以了吗
2008-12-11 11:44
快速回复:fileupload问题?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.018585 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved