I have Memberships and Bookings tables in a database containing an attribute cust_id, which is the primary key in Memberships and reference key in Bookings. When I am executing a data reader I want it to read cust_id values from membership table but it is reading it from the bookings table.
Also, when I compare two cust_id values, 1 taken from a textbox and the other taken a from database column, even though both are the same, but the comparison result is false. I have compared using string.equals(str1, str2) and have also compared the two directly using if statement. But in both cases, even if the string is the same, the result is otherwise.
My query is:
str2 = "select Memberships.cust_id from Memberships, Bookings where Memberships.cust_id = Bookings.cust_id"
Dim cmd2 As New SqlCommand(str2, con)
con.Open()
Dim bookchk As SqlDataReader = cmd2.ExecuteReader
While bookchk.Read()
Dim str1 As String = MskdTxtCustId.Text
Dim str3 As String = bookchk("cust_id")
MessageBox.Show(str1 & "," & str3 & String.Equals(str1, str3))
End While
bookchk.Close()
con.Close()
Try explicitly stating that you want an
INNER JOINinstead:When comparing, use
String.Compare(), and make sure you’re trimming whitespace, just in case.