【问题标题】:Triggers sql(change type column)触发 sql(更改类型列)
【发布时间】:2012-07-15 01:00:10
【问题描述】:

我需要选择数据,最后我需要将date_paymentDateTime 的列更改为Text,请帮助...

我写了这个查询

SELECT r.id, user_name, user_phone, date_create, REPLACE( date_payment,  '0000-00-00 00:00:00',  'No payment' ) , payment_method, amount, rs.name_ru
FROM request AS r, request_status AS rs
WHERE r.status = rs.id
LIMIT 0 , 30

在sql控制台查询是有效的,date_payment是replase,但是:

MySqlCommand cmd = new MySqlCommand(query, conn);

        dt.Load(cmd.ExecuteReader());

        GetList();

        source.DataSource = dt;
dataGrid1.ItemsSource = source;

那么 datagrid 中的 column(date_payment) 为空 - 为什么?

【问题讨论】:

    标签: c# mysql sql wpf datagrid


    【解决方案1】:

    您的计算列没有任何名称。在您的程序中添加“AS updated_date_payment”关键字并请求“updated_date_payment”列:

    SELECT r.id, user_name, user_phone, date_create, REPLACE( date_payment,  '0000-00-00 00:00:00',  'No payment' ) AS updated_date_payment, payment_method, amount, rs.name_ru
    FROM request AS r, request_status AS rs
    WHERE r.status = rs.id
    LIMIT 0 , 30
    
    【解决方案2】:

    使用以下代码:

    SELECT r.id, user_name, user_phone, date_create, REPLACE( date_payment,  '0000-00-00 00:00:00',  'No payment' ) AS date_payment, payment_method, amount, rs.name_ru
    FROM request AS r, request_status AS rs
    WHERE r.status = rs.id
    LIMIT 0 , 30
    

    这里你必须使用 AS 关键字。否则它将返回 *REPLACE( date_payment, '0000-00-00 00:00:00', 'No payment' )* 的列名 (no column name)

    【讨论】:

      猜你喜欢
      • 2021-09-08
      • 2021-08-04
      • 2014-06-07
      • 2020-03-24
      • 2012-08-21
      • 2016-08-27
      • 2013-11-10
      • 1970-01-01
      • 2016-11-02
      相关资源
      最近更新 更多