0

why is it even though i declared correctly the database name and its table, the error always saying TracingApp_fmemployeesuppliersfeedbackquestions is not exists, I just want that if the firstname and lastname exist in the database the record of that i search will show in the DataGridView1

 Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim dt As New DataTable
        Dim firstname = firstnametextbox.Text.Trim()
        Dim lastname = lastnametextbox.Text.Trim()
        Try
            Using MyCon As New Odbc.OdbcConnection("Driver={PostgreSQL ANSI};database=contacttracing;server=localhost;port=5432;uid=*****;sslmode=disable;readonly=0;protocol=7.4;User ID=*****;password=*****;"),
                    cmd As New Odbc.OdbcCommand("SELECT firstname= '" & firstname & "', lastname= '" & lastname & "' FROM TracingApp_fmemployeesuppliersfeedbackquestions ", MyCon)
                MyCon.Open()
                dt.Load(cmd.ExecuteReader)
            End Using
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
        DataGridView1.DataSource = dt
    End Sub

Here is my postgresql tree

enter image description here

this is the error i get

enter image description here

UPDATE

ive tried this also

Odbc.OdbcCommand("SELECT firstname= '" & firstname & "', lastname= '" & lastname & "' FROM public.TracingApp_fmemployeesuppliersfeedbackquestions ", MyCon)

it didnt work also...

7
  • Does it make a difference to fully qualify the table name? FROM public.TracingApp_fmemployeesuppliersfeedbackquestions Commented Oct 22, 2020 at 15:06
  • Odbc.OdbcCommand("SELECT firstname= '" & firstname & "', lastname= '" & lastname & "' FROM public.TracingApp_fmemployeesuppliersfeedbackquestions ", MyCon) , same error, it didnt work mr @NateBarbettini Commented Oct 22, 2020 at 15:09
  • I've never seen anyone arrange for SQL injection by allowing variable column aliases before.. Commented Oct 22, 2020 at 15:16
  • 1
    SELECT * FROM public."TracingApp_tremployeesuppliershousememberssubmittedrecords" ORDER BY id ASC @CaiusJard this is the result Commented Oct 22, 2020 at 15:42
  • 1
    Note: use parameters, the current way you have it is grounds for SQL injection. Commented Oct 22, 2020 at 18:05

1 Answer 1

2

I suggest to surround the table name in quotes:

"SELECT * FROM ""TracingApp_fmemployeesuppliersfeedbackquestions"" " 

"" being what one uses to get a single " into a VB string

I suggest this because I'm aware that PG converts all non quoted table names to lowercase (as can be seen in your "relation does not exist" error message) but the query tool tree shows that some letters in the table names are upper case, so I suspect the table names were created as case sensitive, and TracingApp_fmemployeesuppliersfeedbackquestions is different to tracingapp_fmemployeesuppliersfeedbackquestions

It might be less annoying for you to change your table names, if no other app is using the database, so you don't have to fill your VB strings up with lots of ""

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.