我上传文件到我的目录,现在成功我想获取文件名和路径显示在我的GridView并保存路径到我的DB ...我的问题是,我的网页没有显示在我的网页上,没有保存在数据库中,请帮忙!Gridview不显示和数据不保存在数据库中
protected void Button2_Click(object sender, EventArgs e)
{
if (FileUpload1.PostedFile != null)
{
string FileName = FileUpload1.PostedFile.FileName.ToString();
FileUpload1.SaveAs(Server.MapPath("file_folder/" + FileUpload1.PostedFile.FileName));
string strconString = System.Configuration.ConfigurationManager.ConnectionStrings["ToolkitdbConnectionString"].ConnectionString;
SqlConnection con = new SqlConnection(strconString);
string strQuery = "insert into FileInfo (FileName, FilePath) values(@FileName, @FilePath)";
SqlCommand cmd = new SqlCommand(strQuery);
cmd.Parameters.AddWithValue("@FileName", FileName);
cmd.Parameters.AddWithValue("@FilePath", "file_folder/" + FileName);
cmd.Connection = con;
con.Open();
string[] filespaths = Directory.GetFiles(@"C:\NectarSoft\Projects\Nectarsofttoolkit\Nectarsofttoolkit\file_folder");
Response.Write("Upload successfull");
GridView1.DataBind();
你在上面的代码中执行查询的地方? – 2014-12-08 09:10:15
您永远不会执行查询或该代码段不完整。请仔细检查你的问题,因为它是无用的,因为它是 – Leo 2014-12-08 09:12:13
其中是GridView1.DataSource属性? – 2014-12-08 09:13:56