我需要选择数据,最后我需要将date_payment
更改为DateTime
到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
将被重播,但是:
MySqlCommand cmd = new MySqlCommand(query, conn);
dt.Load(cmd.ExecuteReader());
GetList();
source.DataSource = dt;
dataGrid1.ItemsSource = source;
然后datagrid中的列(date_payment)为空 - 为什么?
答案 0 :(得分:0)
您计算的列没有任何名称。添加“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
答案 1 :(得分:0)
使用以下代码:
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','无付款')*的列名称为(无列名称)