我正在做一个学校项目,在ExecuteNonQuery Sqlcommand之后遇到了这种情况
import React, { Component } from 'react'; // let's also import Component
// the clock's state has one field: The current time, based upon the
// JavaScript class Date
type ClockState = {
time: Date
}
// Clock has no properties, but the current state is of type ClockState
// The generic parameters in the Component typing allow to pass props
// and state. Since we don't have props, we pass an empty object.
export class Clock extends Component<{}, ClockState> {
// The tick function sets the current state. TypeScript will let us know
// which ones we are allowed to set.
tick() {
this.setState({
time: new Date()
});
}
// Before the component mounts, we initialise our state
componentWillMount() {
this.tick();
}
// After the component did mount, we set the state each second.
componentDidMount() {
setInterval(() => this.tick(), 1000);
}
// render will know everything!
render() {
return <p>The current time is {this.state.time.toLocaleTimeString()}</p>
}
}
如您所见,我在msgbox中应用了三元语句,条件是命令执行良好。我对其进行了测试,并执行了该程序,但由于>“ Update Success!Acctid 1”(acctid.text已连接)错误,程序崩溃了。字符串到整数,强制转换异常 从字符串“ Update Success!Acctid 1”到类型“ Integer”的转换无效。
那是为什么?显然,返回必须是字符串,并且该语句中的任何内容都不应启动从字符串到整数的转换。首先是另一种方式,这是两个字符串的有效连接
答案 0 :(得分:1)
“我在msgbox中应用了三元语句” 。嗯,不,你没有。您仅向MsgBox
提供了三个参数,而与该函数的期望无关。 VB中的三元运算符为If
,并且您的代码中没有If
。如果要使用三元运算符,则需要使用一个:
MsgBox(If(c.ExecuteNonQuery > 0, "Update Success! Acctid " & acctid.Text, "Update Failed!"))