开发者

Conversion from string to type 'Double' is not valid

I am getting the following error while running a select statement (using OleDbCommand).

My query is

SELECT CME 
  FROM Personnel 
 WHERE CME = '11349D'

If objOleDbCom.ExecuteScalar() > 0 Then

When i execute the above statement i got this error

Conversion from string "11349D" to开发者_运维知识库 type 'Double' is not valid.

My field CME data type is Text

My database is Access 2007

I tried by running my query directly inside database and it is running fine.

Please suggest.

Thanks.


ExecuteScalar simply returns the column 0, row 0 field in the table returned by your sql. I think what you really want is

SELECT COUNT(1) FROM Personnel WHERE CME = '11349D'


A double is a number (CME seems to be of that type) while '11249D' is a string. They cannot be compared.

What happens when you try:

SELECT CME 
  FROM Personnel 
 WHERE CME = 11349


WHERE CME = '11349D'

should be

WHERE CME = 11349

No '


I just tried actually i was doing the wrong way to check the existence of a record.

i was expecting count of records by running objOleDbCom.ExecuteScalar() and then matching in the if statement which was

"If objOleDbCom.ExecuteScalar() > 0 Then"

now i am using

Dim _strSelectCME As String = "SELECT CME FROM Personnel WHERE CME = '"
Public Function IsPersonnelExits(ByVal p_strCME As String) As Boolean
Dim objOleDbCom As 
    New OleDbCommand(_strSelectCME & p_strCME & "'"
                     , DBRelated.GetDBConnection()
                    )

Dim objObject As Object = objOleDbCom.ExecuteScalar()
If Not IsNothing(objObject) Then
  Return True    
  Exit Function    
End If
Return False
End Function

Problem solved

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜