Hello,
I am have been struggling with this and need some help. I am reading and excel sheet and getting the data and trying to search sql server to get the record. IN excel the length is 12 characters and in sql its 30. I am trying a like query and never getting any results. But if I do it in sql I return a value.

VB.NET code

   Dim strSearchText As String
  strSearchText = TextBox2.Text
    Dim sqlquery As String = "Select * from Housedat where (PROPID LIKE '%" & TextBox2.Text & "%')"
    SQL.ExecQuery(sqlquery)
    If SQL.RecordCount < 1 Then Exit Sub
    For Each r As DataRow In SQL.DBDT.Rows
        TextBox3.Text = r("TAXOWNER")
    Next

SQL Code
SELECT * FROM [dbo].[HousDat] where PROPID LIKE '00092 0100016%' order by PROPID GO

Any help would be great.
Thanks,
Mike

Recommended Answers

All 2 Replies

Looks like there is a comparison between a numeric value (PROPID) and a string ('%" & Textbox2.Text & "%' ). The solution is to convert both to same type by means of CAST or CONVERT:
Syntax for CAST:
CAST ( expression AS data_type [ (length ) ])
or
Syntax for CONVERT:
CONVERT ( data_type [ ( length ) ] , expression [ , style ] )

strSearchText = TextBox2.Text
Dim sqlquery As String = "Select * from Housedat where (PROPID LIKE '%" & TextBox2.Text & "%')"
Why do you not using the 'strSearchText' ? In Sql Query any string type condition must be within a single quation.

  strSearchText = TextBox2.Text
    Dim sqlquery As String = "Select * from Housedat where (PROPID LIKE '%'" & strSearchText & "'%')"

But it was better if you use a parameterised query.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.