【问题标题】:How to add user defined row into a datatable?如何将用户定义的行添加到数据表中?
【发布时间】:2015-11-22 14:03:00
【问题描述】:

我有 datagridview,当单击按钮时,它填充了来自 DB 的值。

所有这些都是基于单选按钮的条件发生的。

现在我需要在数据表中添加一些额外的行(默认值),每次这些条件适用时。

当点击按钮并应用单选按钮条件时,会发生这些代码。

if (radioButton1.Checked == true)
        {
            string query = "SELECT type,priceS FROM service WHERE type='" + button5.Text + "'";
            MySqlCommand cmd = new MySqlCommand(query, con);
            dt.SelectCommand = cmd;
        }dt.Fill(tt);                
            dataGridView1.DataSource = tt;

查询将返回

string =type 和 int=priceS

来自 DB,我只需要添加带有“type”值的字符串“S”

例如:如果 type = Style 那么在数据表中它应该是“Style(S)”

感谢任何帮助。

【问题讨论】:

    标签: c# datagridview datatable


    【解决方案1】:

    我没有使用数据表,而是在 MySQL 查询本身中解决了它

    Query="Select Concat(type,'S'),price from service"

    这会将字符串 S 与类型值相加。

    【讨论】:

      猜你喜欢
      • 2011-02-17
      • 2015-10-18
      • 1970-01-01
      • 1970-01-01
      • 2021-01-02
      • 1970-01-01
      • 2021-12-02
      • 1970-01-01
      • 2021-02-02
      相关资源
      最近更新 更多