我写了一段上传的程序,为什么可以上传到文件夹里,但却没有把文件标题,创建时间等记录到数据库里呢?

解决方案 »

  1.   

    回复:程序如下:protected void Button1_Click(object sender, EventArgs e)
        {
            string str = this.FileUpload1.PostedFile.FileName;
            string filepath;
            string ss = str.Substring(str.LastIndexOf("\\") + 1);
            string s = Server.MapPath("..\\neos\\" + ss);
            filepath = "..\\neos\\" + ss;
            bool bl = ExecSQL("INSERT INTO [file3](fileDescription,filepath)VALUES('" + TextBox1.Text + "','" + filepath + "')");
            if (bl)
            {
                Response.Write("<script language = javascript>alert(\"上传文件成功!\")</script>");
            }
            else
            {
                Response.Write("<script language = javascript>alert(\"上传文件失败!\")</script>");
            }
            if (str == string.Empty) return;
            this.FileUpload1.PostedFile.SaveAs(s);
        }    public Boolean ExecSQL(string sQueryString)
        {
            string ConnectionString = "Data Source=localhost;Initial Catalog=abs;Persist Security Info=True;User ID=sa;Password=m123";
            SqlConnection cn = new SqlConnection(ConnectionString);
            SqlCommand dbCommand = new SqlCommand(sQueryString, cn);
            try
            {
                dbCommand.ExecuteNonQuery();
                cn.Close();
            }
            catch (SystemException e)
            {
                cn.Close();
                return false;
            }
            return true;
        }