C#如何插入数据库

标签 c# mysql

我需要这方面的帮助,我正在将文件目录插入数据库,但它没有考虑数据库中的 txtStoryTitle.Text,例如,如果我在 txtStoryTitle 中键入 HelloWorld。它在数据库中显示为 Images/Story//(filename) 而不是 Images/Story/HelloWorld/(filename)。我正在使用 MySQL(工作台)。

请给我对此的建议/解决方案,提前致谢!

部分代码如下:

    protected void AjaxFileUpload1_UploadComplete(object sender, AjaxControlToolkit.AjaxFileUploadEventArgs e)
    {
        EnsureDirectoriesExist();


        String filepathImage = (@"Images/Story/" + txtStoryTitle.Text + "/" + e.FileName);


        AjaxFileUpload1.SaveAs(Server.MapPath(filepathImage));


        Session["filepathImage"] = filepathImage;

    }

   public void EnsureDirectoriesExist()
    {
        if (!System.IO.Directory.Exists(Server.MapPath(@"Images/Story/" + txtStoryTitle.Text + "/")))
        {
            System.IO.Directory.CreateDirectory(Server.MapPath(@"Images/Story/" + txtStoryTitle.Text + "/"));
        }
    }

 protected void btnDone_Click(object sender, EventArgs e)
    {
        if (Session["filepathImage"] != null)
        {
            string filepathImage = Session["filepathImage"] as string;
            act.ActivityName = dropListActivity.SelectedItem.Text;
            act.Title = txtStoryTitle.Text;

            act.FileURL = filepathImage;

            daoStory.Insert(act);
            daoStory.Save();

        }

最佳答案

根据您的代码..文件路径为“Images/Story/”+ txtStoryTitle.Text +“/”+ e.FileName” 提供 txtStoryTitle.Text 后,将其保存为“Images/Story//FileName”.. 那么这意味着 txtStoryTitle.Text 不包含任何文本..

如果是在 .Net 中,请确保将 txtStoryTitle 文本框的 autopostback 属性设置为 true。 如果它已经是真的,那么尝试找出为什么这个文本框不抵抗它的状态。

关于C#如何插入数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16580419/

相关文章:

c# - 从没有数据的查询中获取列名

c# - Lucene - 对子句计数的评分效果

mysql - 如何将 MySQL 变量与 POINT 一起使用

Java 数据库 ID - 原始类型或包装类型

PHP 登录问题 - mysql_num_rows 无效

c# - 将 SQLiteNetExtension 与 SQLite-net 集成到 Xamarin 解决方案中

c# - Foreach with continue -- 意外行为

c# - 如果您仅更改值,List<T> 线程安全吗?

php - SQL:动态扩展搜索条件

mysql查询需要不同的结构