String query error
I make a query in coding. But I got conversion error. Please check my fault.
My query is below
Dim strSelect As String = ""
strSelect = "SELECT " & _
"Description As [Desc], " & _
"iif(CurCons = 0, " - ", CurCons) As [CCQty] " & _
"FROM tblCur"
Exception error is like
Conversion from string "iif(CurCons = 0, " to type 'Double' is not valid
Acturally, in my report, i wanna show if it's zero then '-'. If i set it in this string. I got another error like below
开发者_如何学CThe provider could not determine the Decimal value. For example, the row was just created, the default for the Decimal column was not available, and the consumer had not yet set a new Decimal value.
From da.Fill
Dim cmd As New OleDbCommand(strDynamic, m_DBConn)
Dim da As New OleDbDataAdapter(cmd)
da.Fill(ds, "tblCur")
How to solve this?
strSelect = "SELECT " & _
"Description As [Desc], " & _
"IIF(CurCons = 0 OR ISNULL(CurCons), ' - ', CStr(CurCons)) As [CCQty] " & _
"FROM tblCur"
You are still in the SQL Query when you are doing the IIF statement, so you do not want to use the " characters for strings, instead you will use '.
Your report would need the field where the value is outputted to be set to the Text type, otherwise you will see an error.
You are using double quotes to quote the string as well as to quote "-"
. This will not work because it closes the string, so the dash is interpreted literally as a subtraction operator. You should try something like:
"iif(CurCons = 0, '-', CurCons) As [CCQty] " & _
This uses single quotes for the dash.
精彩评论