我想創建條件來更新我的表,如果已經有相同的數據(在同一列)插入表中。如何使條件更新表?
IM使用
If String.ReferenceEquals(hotel, hotel) = False Then
insertDatabase()
Else
updateDatabase()
End If
這是updateDatabase()的代碼...
Dim sql2 As String = "update infoHotel set nameHotel = N" & FormatSqlParam(hotel) & _
", streetAddress = N" & FormatSqlParam(StreetAddress) & _
", locality = N" & FormatSqlParam(Locality) & _
", postalCode = N" & FormatSqlParam(PostalCode) & _
", country = N" & FormatSqlParam(Country) & _
", addressFull = N" & FormatSqlParam(address) & _
", tel = N" & FormatSqlParam(contact) & _
"where hotel = '" & hotel & "')"
這是formatSqlParam()代碼:
Function FormatSqlParam(ByVal strParam As String) As String
Dim newParamFormat As String
If strParam = String.Empty Then
newParamFormat = "'" & "NA" & "'"
Else
newParamFormat = strParam.Trim()
newParamFormat = "'" & newParamFormat.Replace("'", "''") & "'"
End If
Return newParamFormat
End Function
功能設法去到updateDatabase(),但有一些錯誤說
「東方'附近語法不正確。」
東方是插入在表中的數據。它適合使用ReferenceEquals嗎?
用vb.net和SQL database..tq
1)向我們展示'updateDatabase()'的代碼。 2)這種比較總是**是「真實的」。 – egrunin 2010-06-11 03:05:07