【问题标题】:Upload data into sql table将数据上传到sql表
【发布时间】:2021-06-12 15:51:53
【问题描述】:

这是给我的代码:

 protected void btnAdd_Click(object sender, EventArgs e)
        {
            divTempForm.Visible = true;
            rptMailTemplate.Visible = false;

            mMailTemplate mail = new mMailTemplate();
            mail.MailTempleteCode = txtMailTempCode.Text;
            mail.Subject = txtMailSubject.Text;
            mail.InsertedBy = _objUserIdentity.UserID;
            mail.Body = hdsummernote.Value;
            mail.MailBodyType = ddlMailBodyType.SelectedValue;
            //mail.Active = lblActive.Text;
            mail.Active = "Y";



            DataSet ds = mtc.InsertMailTemplate(mail);
            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["out_msg"].ToString() == "RecordAdded")
                {
                    if (fuImg.HasFile)
                    {
                        fuImg.SaveAs(Server.MapPath("~/MailerImages/" + ds.Tables[0].Rows[0]["MailTemplateID"] + "_" + fuImg.FileName));

                        **mail.BodyImagePath = @"\MailerImages\" + ds.Tables[0].Rows[0]["MailTemplateID"] + "_" + fuImg.FileName;**
                    }
                }
            }
            Response.Redirect("MotivationUI.aspx");
        }

基本上,这段代码所做的是将文本框中的值添加到 sql server 中。但我需要 mail.BodyImagePath 的帮助。该文本为存储在服务器上的图像位置创建了一个 URL,我需要将该“URL”存储到 sql 表中。知道我应该怎么做吗?

【问题讨论】:

  • 那么,您的问题是关于如何进行数据库更新还是如何从 DataTable 中获取值?我也看不到从 mMailTemplate 获取 DataSet 的原因。
  • mMailTemplate 包含所有的 getter 和 setter public class mMailTemplate { public string MailTemplateID { get;放; } 公共字符串 MailTempleteCode { 获取;放; } 公共字符串主题 { 获取;放; } 公共字符串正文 { 获取;放; } 公共字符串活动 { 获取;放; } 公共字符串 InsertedBy { 获取;放; } 公共字符串 DefaultAttachment { 获取;放; } 公共字符串 HasIndAttachment { 获取;放; } 公共字符串 MailBodyType { 获取;放; } 公共字符串 BodyImagePath { 获取;放; } }
  • 我想将 mail.BodyImagePath 中存储的值插入到 SQL 表中名为 BodyImagePath 的列中
  • 我能认出这是一门课。我不明白为什么你会从一个类的单个实例中获取一个 DataSet。 InsertMailTemplate 是做什么的?还有,究竟你遇到的问题是什么?
  • 在电子邮件接收地址应该有一个应用程序应该自动将数据保存到数据库中。你打算写那个应用程序吗?

标签: c# sql asp.net .net


【解决方案1】:

只需将图像路径保存在 if 条件中的字符串变量中,然后使用您的 sql 查询对其进行更新:

string path = @"\MailerImages\" + ds.Tables[0].Rows[0]["MailTemplateID"] + "_" + fuImg.FileName;

Update table set columnName = path where //your condition here;

注意:在 Response.Redirect("MotivationUI.aspx"); 之前或在为变量分配路径之后的 if 条件内执行此操作。

【讨论】:

    猜你喜欢
    • 2021-12-02
    • 2015-08-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-18
    • 1970-01-01
    • 2019-12-24
    • 1970-01-01
    相关资源
    最近更新 更多