0
在VB.Net中,我试图检查数据库中是否已经存在某个值对。如果不是,则需要添加:如何检查数据库中是否存在值对?
Public Shared Sub updateChoice(ByVal dbConn As NS.DBConn, ByVal Y As String, ByVal Z As Int32)
'check if the Y <=> Z pair already exists
Dim sqlText As String = "select from table where X = " & CStr(Y)" and Y =" &CStr(Z)
Dim pairExists = dbConn.ExecuteAsDataSet(sqlText)
If (pairExists <= 0) Then
Dim sqlText As String = "insert into table ..." ' Insert pair into DB
dbConn.ExecuteNonQuery(sqlText)
End If
End Sub
的Visual Studio使我对If (pairExists <= 0) Then
的错误:Operator <= is not defined for types System.Data.DataSet and Integer
我有一个很难理解这个错误。我究竟做错了什么?
消息很明确。 pairExists是一个DataSet,而不是一个整数。您无法将这两种类型进行比较。 – Crowcoder 2014-10-03 09:37:49
那我用错了吗?我只是想检查对是否已经存在,并且需要使用整数或TRUE/FALSE分配pairExists? – Pr0no 2014-10-03 09:39:43
您想要使用ExecuteScalar而不是ExecuteasDataset,但是查询显示为没有任何列,所以请确保您修复该问题并在select子句中只定义一列。 – Crowcoder 2014-10-03 09:42:53