猿问

在我的 TableAdapter 中使用 If 语句时发生错误

我目前在我以前的项目中使用 VB.NET。现在,从 VB.NET 切换到 C#。我尝试了一个在线转换器,但它似乎不起作用。我收到以下错误:


无法将 int 类型隐式转换为 bool。


这是我的代码:


String verify = txtVerify.Text;


if (tblStudentTableAdapter.FillByVerifyStudent(dbInfoDataSet.tblStudent, verify, verify, verify))

{

    MessageBox.Show("Matched");

}

else

{

    MessageBox.Show("No Result");

}

在 VB.NET 中,它没有问题。请给我一个关于如何解决这个问题的想法。先感谢您


VB.NET 中的代码:


Dim verify as String = txtVerify.Text;


if tblStudentTableAdapter.FillByVerifyStudent(dbInfoDataSet.tblStudent, verify, verify, verify) Then

    MessageBox.Show("Matched");

else

    MessageBox.Show("No Result");

End If


眼眸繁星
浏览 87回答 1
1回答

慕神8447489

您可以使用Convert.ToBoolean(int)方法转换int为bool. true如果 的值int不为零,则此方法将返回。String verify = txtVerify.Text;if (Convert.ToBoolean(tblStudentTableAdapter.FillByVerifyStudent(dbInfoDataSet.tblStudent, verify, verify, verify))){    MessageBox.Show("Matched");}else{    MessageBox.Show("No Result");}
随时随地看视频慕课网APP
我要回答