1
行が存在し、ExecuteReaderを正しく使用するかどうかを知る必要がありますか?行が存在するかどうかを確認するクエリ
私のコードはちょうど私が行く予定のアイデアを与える。
Const c_str_SELECT_SQL As String = "SELECT Fails FROM LoginAttacks WHERE IP = ?"
If Not String.IsNullOrEmpty(strPointsDBConnectionString) Then
objOLEConnection = New OleDbConnection(strPointsDBConnectionString)
objOLEConnection.Open()
objOLECommand = New OleDbCommand(c_str_SELECT_SQL, objOLEConnection)
objIP = objOLECommand.Parameters.Add("@IP", OleDbType.Char)
objIP.Value = Me.IPAddress
' Connect execute update query
FailedCounts = CInt(objOLECommand.ExecuteScalar())
If FailedCounts > 0 Then 'need to find way to tell if query worked/found row with ip
FailedCounts = FailedCounts + 1
'Did not fail assume worked so go use update function
IPExist = True 'if not go use insert function
End If
Else
Throw New Exception(const_CONNECTION_STRING_ERROR)
End If
UPDATE:
私が追加:
objOLEDataReader = objOLECommand.ExecuteReader()
If objOLEDataReader.HasRows Then
'Do While objOLEDataReader.Read()
FailedCounts = CInt(objOLECommand.ExecuteScalar())
FailedCounts = FailedCounts + 1
'Did not fail assume worked so go use update function
IPExist = True 'if not go use insert function
'Loop
Else
'none found
End If
objOLEDataReader.Close()
をしかし、私は偶数行でIF文に入ることがないようです。