以下查询尝试将class ThirdRouteState extends State<ThirdRoute> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Calendar Page"),
),
body: Column(children: <Widget>[
Table(
children: <TableRow>[
TableRow(
children: getDaysInWeek(),
),
TableRow(
children: getSevenInWeek(),
),
],
),
]),
);
}
}
List<Widget> getSevenInWeek() {
var seven = <DateTime>[];
DateTime start = DateTime(2019, 01, 01);
final end = DateTime(2019, 01, 08);
while (start.isBefore(end)) {
seven.add(start);
start = start.add(const Duration(days: 1));
}
return seven.map((DateTime time) {
return Text(
new DateFormat("dd").format(time),
style: TextStyle(backgroundColor: Colors.red),
textAlign: TextAlign.left,
);
}).toList();
}
List<Widget> getDaysInWeek() {
List<Widget> dayWidgets = [];
Utils.weekdays.forEach(
(day) {
dayWidgets.add(
new CalendarTile(
isDayOfWeek: true,
dayOfWeek: day,
),
);
},
);
return dayWidgets;
}
数据类型转换为varchar
,但是不起作用。你知道为什么吗?
int
我得到了错误:
第245级状态1状态2线
时,转换失败
将varchar值'3893.768'转换为数据类型int
答案 0 :(得分:1)
很明显,您的字符串具有小数部分,因此您不能将其直接转换为整数。
一种解决方案是先将CAST
设置为浮点数,然后再设置为整数,例如:
SELECT CAST( CAST([BR] AS FLOAT) AS INT) AS CC FROM [Seg].[dbo].[pro_ben]
SELECT CAST('3893.768' AS FLOAT)
| (No column name) | | ---------------: | | 3893.768 |
SELECT CAST( CAST('3893.768' AS FLOAT) AS INT)
| (No column name) | | ---------------: | | 3893 |
答案 1 :(得分:1)
该值不是整数。这为您提供了多种选择:
try_convert()
来返回NULL
。numeric()
。转换为numeric
会忽略小数点,但它们不会引起错误:
SELECT convert(numeric(10,0), [BR]) as dd
FROM [Seg].[dbo].[pro_ben];
如果您特别需要该类型,则可以将其转换为int
。
答案 2 :(得分:0)
mmmm一旦我将数据类型更改为float,它就会出现,它可以工作。
答案 3 :(得分:0)
我会尝试
Select Round([BR],0) as dd
FROM [Seg].[dbo].[pro_ben];