asp.net上传文件到sql
来源:百度知道 编辑:UC知道 时间:2024/05/31 16:45:47
用vs2005往sql2000中上传文件,代码如下,为什么运行时候不报错,但也进不了数据库,请各位帮忙看看是怎么回事~~~
string name = TextBox1.Text;
//接收上传文件
Stream fileStream = FileUpload1.PostedFile.InputStream;
//获取上传文件字节的大小
int length = FileUpload1.PostedFile.ContentLength;
byte[] wordData = new byte[length];
//从流中读取字节并写入wordData
int n = fileStream.Read(wordData, 0, length);
//获取当前时间
DateTime time = DateTime.Now;
SqlConnection strcon = new SqlConnection(ConfigurationManager.AppSettings["conStr"]);
strcon.Close();
strcon.Open();
SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["conStr"]);
SqlCommand cmd = new SqlCommand("INSERT INTO file (filename,filecontent,posttime) values (@fileName,@fileContent,@posttime)");
//cmd.
string name = TextBox1.Text;
//接收上传文件
Stream fileStream = FileUpload1.PostedFile.InputStream;
//获取上传文件字节的大小
int length = FileUpload1.PostedFile.ContentLength;
byte[] wordData = new byte[length];
//从流中读取字节并写入wordData
int n = fileStream.Read(wordData, 0, length);
//获取当前时间
DateTime time = DateTime.Now;
SqlConnection strcon = new SqlConnection(ConfigurationManager.AppSettings["conStr"]);
strcon.Close();
strcon.Open();
SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["conStr"]);
SqlCommand cmd = new SqlCommand("INSERT INTO file (filename,filecontent,posttime) values (@fileName,@fileContent,@posttime)");
//cmd.
//cmd.ExecuteNonQuery(); --你都注释掉了 根本就没有执行入库操作 没有报错说明数据库连接是正常的 因为有执行con.open
而且还有一个问题 你这里也没有把cmd和con关联