Click here to Skip to main content
15,917,176 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Can Any one plese Guide what is the error below is my code

VB
If Txt_Plannr.Text = "" And Txt_Titel.Text <> "" Then
                Dim Sql As New OleDbCommand("SELECT Plannr, Titel1 From TblPlannenLijst where Titel1 Like " & Chr(34) & "*" & Txt_Titel.Text & "*" & Chr(34) & " And  Soort='01 Company_BIK'  order by Plannr", dbConnection)
                Dim connection1 As New OleDbConnection(connectiontring)
                Dim reader1 As OleDbDataReader = Sql.ExecuteReader()
                While (reader1.Read())
                    ' Add  items
                    TempStr(0) = reader1.Item(0).ToString()
                    TempStr(1) = reader1.Item(1).ToString()
                    TempNode = New ListViewItem(TempStr)
                    Lst_Blocks.Items.Add(TempNode)
                End While
                reader1.Close()
            Else
                Dim command As New OleDbCommand("SELECT Plannr, Titel1 FROM TblPlannenLijst where Soort='01 Company_BIK' order by Plannr", dbConnection)
                Dim connection As New OleDbConnection(connectiontring)
                Dim reader As OleDbDataReader = command.ExecuteReader()
                While (reader.Read())
                    ' Add  items
                    TempStr(0) = reader.Item(0).ToString()
                    TempStr(1) = reader.Item(1).ToString()
                    TempNode = New ListViewItem(TempStr)
                    Lst_Blocks.Items.Add(TempNode)
                End While
                reader.Close()
End If
            dbConnection.Close()


Else part is working but the condition is not working
Access database Query is running but no items added to the list view

Please Guide
Posted
Updated 19-Oct-15 5:13am
v2
Comments
Richard Deeming 19-Oct-15 10:49am    
Your code is vulnerable to SQL Injection[^].

NEVER use string concatenation to build a SQL query. ALWAYS use a parameterized query.
Maciej Los 19-Oct-15 11:14am    
Are you sure that reader1 contains any data?
Bensingh 20-Oct-15 2:09am    
ya while I have checked in the data base its have the value of 1 row
Bensingh 20-Oct-15 3:48am    
Me itself fixed the solution is
Dim Sql As New OleDbCommand("SELECT Plannr, Titel1 From TblPlannenLijst where Titel1 Like '%" & Txt_Titel.Text & "%' And Soort='01 Company_BIK' order by Plannr", dbConnection)
Need to change the syntax

1 solution

Change the Like Query as

VB
Dim Sql As New OleDbCommand("SELECT Plannr, Titel1 From TblPlannenLijst where Titel1 Like '%" & Txt_Titel.Text & "%' And Soort='01 Company_BIK' order by Plannr", dbConnection)
 
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