我使用以下查询:
string query = @"SELECT r.id, user_name, user_phone, date_create, REPLACE( date_payment, '0000-00-00 00:00:00', 'Не оплачено' ) as
date_payment, payment_method, amount, rs.name_ru
FROM request AS r, request_status AS rs
WHERE r.status = rs.id";
我以下列方式绑定datatemplate:
DataTemplate>
<TextBlock VerticalAlignment="Center" Text="{Binding date_payment}" Width="135" />
</DataTemplate>
除了“ date_payment ”之外,其输出正确的输出其输出值为“ System.Byte [] ”。 请帮忙!!!
感谢MBen
class ByteArrayToString : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value != null)
{
var listOfBytes = value as Byte[];
string output = "";
output = System.Text.Encoding.UTF8.GetString(listOfBytes);
return output;
}
return "";
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return DependencyProperty.UnsetValue;
}
}
答案 0 :(得分:2)
date_payment
是一个数组,并且您没有为WPF提供任何显示方式,因此它调用ToString
。您可以为它提供数据转换器。
将资源添加到您的窗口或页面:
<Window.Resources>
<local:ByteArrayToString x:Key="ByteArrayConverter" />
</Window.Resources>
在TextBlock
中使用它:
<TextBlock VerticalAlignment="Center" Text="{Binding date_payement, Converter={StaticResource ByteArrayConverter}}" Width="135" />
现在您需要添加一个执行转换的新类:
class ByteArrayToString : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value != null)
{
var listOfBytes = value as Byte[];
string output ="";
output = listOfBytes.Aggregate(output, (current, elemt) => current + elemt.ToString());
return output;
}
return "";
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return DependencyProperty.UnsetValue;
}
}
答案 1 :(得分:0)
这件事发生在我身上。这似乎是由于连接器中的错误。尝试将日期列转换为CHAR。它对我有用。