0

我需要选择数据,最后我需要date_paymentDateTimeto更改列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) 为空 - 为什么?

4

2 回答 2

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
于 2012-07-16T08:03:11.380 回答
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', 'No payment' )* 的列名返回为(无列名)

于 2012-07-16T08:17:49.367 回答