Salve,
devo tradurre delle librerie d vb a c#, e mi sono imbattuto in questo problema, che né i tool di conversione, né io riusciamo ad aggirare.
Questa è la parte in vb:
codice:
Public Function isLoginDuplicate(ByVal login As String) As Long
Dim strSql As String
Dim command As OleDbCommand
strSql = "SELECT count(*) FROM " & SchemaName + TableName
strSql = strSql & " WHERE loginname = '" & login.ToUpper & "'"
strSql = strSql & " and key <> " & Key
command = New OleDbCommand(strSql, dbConnection.connect())
If (command.ExecuteScalar())
Then
Return True
Else
Return False
End If
E questa è la relativa conversione in C#:
codice:
public long isLoginDuplicate(string login)
{
string strSql = null;
OleDbCommand command = null;
strSql = "SELECT count(*) FROM " + SchemaName + TableName;
strSql = strSql + " WHERE loginname = '" + login.ToUpper() + "'";
strSql = strSql + " and key <> " + Key;
command = new OleDbCommand(strSql, dbConnection.connect());
if ((command.ExecuteScalar())) {
return true;
} else {
return false;
}
}
Però mi dà questo errore: CS0266: Impossibile convertire in modo implicito il tipo 'object' in 'bool'. È presente una conversione esplicita. Probabilmente manca un cast.
L'errore è riportato alle righe sottolineate...
Se manca un cast, dove e come lo aggiungo?
Grazie in anticipo