SQL DATEDIFF()及其在asp.net中的使用
我使用sqlSQL DATEDIFF()及其在asp.net中的使用,asp.net,datediff,Asp.net,Datediff,我使用sqlDATEDIFF()(返回类型:int)函数减去两次,并在asp.net应用程序中使用该值(以分钟为单位)。如果分钟数大于30,则应为红色。但我得到一个错误“输入字符串的格式不正确。” SQLDATEDIFF()函数 Update lunTime set lunTot = DATEDIFF(minute, lunIn, LunOut) from lunTime 现在在gridview中使用该值 if (e.Row.RowType == DataControlRowType.Dat
DATEDIFF()
(返回类型:int)函数减去两次,并在asp.net应用程序中使用该值(以分钟为单位)。如果分钟数大于30,则应为红色。但我得到一个错误“输入字符串的格式不正确。”
SQLDATEDIFF()
函数
Update lunTime
set lunTot = DATEDIFF(minute, lunIn, LunOut) from lunTime
现在在gridview中使用该值
if (e.Row.RowType == DataControlRowType.DataRow)
{
int lunTot = Convert.ToInt16(e.Row.Cells[4].Text);
if (lunTot > 30)
{
e.Row.ForeColor = Color.Red;
}
}
检查空值。除此之外,代码中没有任何错误
int? lunDateTotl = Int32.TryParse(stringVal, out tempVal) ? tempVal : (int?)null;
if (DBNull.Value != lunDateTotl)
{
lunDateTotl = Convert.ToInt16(e.Row.Cells[4].Text);
}
if (lunDateTotl > 30)
{
e.Row.ForeColor = Color.Red;
}
您还可以按客户端脚本高亮显示行
<asp:Label ID="lblUPSUserName" runat="server" Text='<%# Eval("lunTot") %>' CssClass='<%# Convert.ToInt32(Eval("lunTot")) > 30 ? "__IsActive" : "" %>'></asp:Label>
和在脚本块中
<script type="text/javascript">
function pageLoad() {
$(".__IsActive").closest('tr').addClass("highLight");
}
</script>
函数pageLoad(){
$(“.IsActive”).closest('tr').addClass(“highLight”);
}
并将类放入您的style.css中
<style type="text/css">
.highLight td {
background-color: green;
}
</style>
.突出显示运输署{
背景颜色:绿色;
}
似乎是e.Row.Cells[4]。文本返回空值或无效值。此外,查询有点奇怪,“from lunTime”在更新查询结束时是什么意思?lunIn=开始时间,lunOut=结束时间,lunTot=lunOut lunIn来自表“lunTime”获取错误:运算符“!=”在与DBNull.Value
进行比较之前,无法应用于“System.DBNull”类型和“string”类型的操作数转换为int。请参阅更新。我尝试过这样做,但得到与ealier相同的错误…:(