It is true that i did not optimized SQL command, only removed worst trash from code. It is hundreds of records at maximum and it is not over network - only locally using SQL Server Compact Edition.
Ondrej Linhart
Posts
-
Epic method to check if database table contains any suitable rows -
Epic method to check if database table contains any suitable rowsIn this case it is something like "marking". Stupid naming in former developer's native language is next horrifying issue.
-
Epic method to check if database table contains any suitable rowsPublic Function CHeckDataPrjVyd(ByVal data As String) As Boolean
Dim cn As System.Data.SqlServerCe.SqlCeConnection
Dim cmd As System.Data.SqlServerCe.SqlCeCommand
Dim dtr As System.Data.SqlServerCe.SqlCeDataReader
Dim i As Integer = 0cn = New System.Data.SqlServerCe.SqlCeConnection("Data Source=" + values.DatabaseFile) cn.Open() cmd = New System.Data.SqlServerCe.SqlCeCommand("SELECT \* FROM data where oznacenie like '" + data + "'", cn) dtr = cmd.ExecuteReader() While dtr.Read i = i + 1 If i = 1 Then CHeckDataPrjVyd = True Exit While End If CHeckDataPrjVyd = False End While cn.Close()
End Function
After cleaning that monstrosity:
Public Function IsDataPresent(ByVal data As String) As Boolean
Using connection As New SqlCeConnection(My.Settings.ConnectionString)
connection.Open()
Dim commandText = String.Format("SELECT * FROM data WHERE oznacenie LIKE '{0}'", data)
Using command As New SqlCeCommand(commandText, connection)
Using reader = command.ExecuteReader()
Return reader.HasRows
End Using
End Using
End Using
End Function