Click here to Skip to main content
15,887,815 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
my problem in SQL query, result has been successful to load data in datagrid like SL_No (2,4,5) but some data are missing from table Pairing like (1,2,3,4,5,6) where relationship table data is not available like (1,3,6) in Receipt table.


What I have tried:

Private Sub BtnView_Click(sender As Object, e As EventArgs) Handles btnView.Click

    Dim Sql as String = "Select Pairing.Ledger_Index, Pairing.Fr_Customer_no, Pairing.Fr_Customer_nm, Receipt.Dt_Entry, Receipt.Price from Pairing INNER JOIN Receipt ON Pairing.Fr_Customer_no = Receipt.Sub_No WHERE (((Pairing.Ledger_Address)='" & cmbList.Text & "'))""

    If RdoLedger.Checked=True Then
       DatagridView_Load("sql",DatagridView1)
    End If

End Sub

Public Function DatagridView_Load(ByVal Sql As String, ByVal Model As DataGridView)
    Try
        If con.State = ConnectionState.Open Then
            con.Close()
        End If
        Model.DataSource = Nothing
        Dim da As New OleDbDataAdapter(Sql, con)
        Dim dt As New DataTable
        dt.Clear()
        da.Fill(dt)
        If IsDBNull(dt) = False Then
            Model.DataSource = (dt)
            con.Close()
        Else
            Model.DataSource = Nothing
            con.Close()
        End If

    Catch ex As Exception
        MsgBox("ERROR : " & ex.Message.ToString)
    End Try
    Return True
End Function
Posted
Updated 29-Jan-20 1:47am
Comments
Richard Deeming 29-Jan-20 7:44am    
Dim Sql as String = "Select Pairing.Ledger_Index, Pairing.Fr_Customer_no, Pairing.Fr_Customer_nm, Receipt.Dt_Entry, Receipt.Price from Pairing INNER JOIN Receipt ON Pairing.Fr_Customer_no = Receipt.Sub_No WHERE (((Pairing.Ledger_Address)='" & cmbList.Text & "'))""

Don't do it like that!

Your code is vulnerable to SQL Injection[^]. NEVER use string concatenation to build a SQL query. ALWAYS use a parameterized query.

Everything you wanted to know about SQL injection (but were afraid to ask) | Troy Hunt[^]
How can I explain SQL injection without technical jargon? | Information Security Stack Exchange[^]
Query Parameterization Cheat Sheet | OWASP[^]
Member 10469183 30-Jan-20 3:06am    
Sir pls suggest this query, how to use SQL Injection[^], pls examle by my query. Thank you.

An INNER JOIN will only return rows where there is a matching record in both tables.

It sounds like you want a LEFT JOIN instead.

Visual Representation of SQL Joins[^]

But seriously, fix that SQL Injection[^] vulnerability before someone deliberately or accidentally uses it to destroy your database!
 
Share this answer
 
Comments
Member 10469183 29-Jan-20 8:12am    
Thank You for reply and i am very poor in programming but i dont know what is SQL Injection[^], i will try to understand this. Thank You.
I would be want all data of pairing table where not may be pairing table data not matching with recipt table but there result in datagrid reciept column data should be zero or not available.
 
Share this answer
 
Comments
Richard Deeming 29-Jan-20 7:43am    
If you want to update your question, click the green "Improve question" link and edit your question.

Do not post your update as a "solution".

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