Click here to Skip to main content
15,897,704 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dim a As String() = {"247.032", "247.038", "009.549", "009.452", "010.328", "009.901", "009.902", "009.948", "247.020", "008.540", "008.978", "009.236", "", "007.821", "007.823", "008.309", "008.310", "008.313", "008.314", "008.472", "008.473", "008.482", "007.821", "008.481", "008.306", "008.307", "010.740", "009.274", "009.275", "007.520", "007.620", "963.709", "007.850"}
            Dim b As String = "5"
            Dim t As String = regCis

            Dim result = a.Any(Function(x) t.StartsWith(x) AndAlso t.EndsWith(b))
            If result = True Then

                provider = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source ="
                dataFile = "sdf.accdb" ' Change it to your Access Database location
                connString = provider & dataFile
                Dim command As New OleDbCommand("SELECT * FROM Log WHERE [Zákaznické číslo] = '" & TextBox2.Text & "'")
                Dim cnn As New OleDbConnection(connString)
                command.Connection = cnn
                Try
                    cnn.Open()
                Catch
                    MsgBox("Připojení k databázi se nezdařilo.", , "Chyba")
                End Try
                dr = command.ExecuteReader

                If dr.HasRows And t.EndsWith(b) = True Then
                    MsgBox("Čárový kód byl již skenován " & TextBox2.Text, , "Chyba")
                    TextBox2.Clear()
                    tiskEtiketaBut.BackColor = Color.DimGray
                    tiskEtiketaBut.Enabled = True
                    TextBox2.Select()
                    myConnection.Close()

                Else


What I have tried:

Here is my code, I would like to paste else condition for result behind else of hashrows . How can I do it? Thank you.

If result is true then next condition look to database if number was scanned. And now I want send else for result and else for hashrows.
Posted
Updated 31-Jul-18 6:36am
Comments
Richard MacCutchan 31-Jul-18 10:38am    
Your question is not clear. Are you saying you do not know how to write an Else clause? You already have the word Else, so what do you need to write for that situation?
[no name] 31-Jul-18 11:10am    
in code is else for if hashrows, I need next else for if result=true then. Next else under else show me error
Richard MacCutchan 31-Jul-18 11:33am    
"show me error"
Well we cannot help you unless you also show it to us.
[no name] 31-Jul-18 12:21pm    
error: Else must be proceded by a matching if or elsif. I dont known what i doing wrong.

1 solution

VB
Dim command As New OleDbCommand("SELECT * FROM Log WHERE [Zákaznické číslo] = '" & TextBox2.Text & "'")

Not a solution to your question, but another problem you have.
Never build an SQL query by concatenating strings. Sooner or later, you will do it with user inputs, and this opens door to a vulnerability named "SQL injection", it is dangerous for your database and error prone.
A single quote in a name and your program crash. If a user input a name like "Brian O'Conner" can crash your app, it is an SQL injection vulnerability, and the crash is the least of the problems, a malicious user input and it is promoted to SQL commands with all credentials.
SQL injection - Wikipedia[^]
SQL Injection[^]
SQL Injection Attacks by Example[^]
PHP: SQL Injection - Manual[^]
SQL Injection Prevention Cheat Sheet - OWASP[^]
How can I explain SQL injection without technical jargon? - Information Security Stack Exchange[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900