Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SqlException was unhandled - search sql db from textbox 2

Status
Not open for further replies.

liamcan

IS-IT--Management
Apr 15, 2009
3
US
Hi,

Any help with this will be greatly appreciated. I am creating an issue tracking with issues and resolutions as the fields. "SqlException was unhandled - An expression of non-boolean type specified in a context where a condition is expected, near ','." is the error message. The coding I used is:
Dim text As String
text = txtSearch.Text
Dim ad As String = "Select * from Iss_Res where Issue, Resolution LIKE" & text
Dim cn As New SqlConnection(ConStr)
Dim cn2 As SqlCommand = New SqlCommand(ad, cn)
cn.Open()
Dim sqlReader As SqlDataReader = cn2.ExecuteReader()
ds = New DataSet
dv = New DataView

Thanks,
liamcan
 

You have incomplete SQL:
Code:
    Dim text As String
    text = txtSearch.Text
    Dim ad As String = "Select * from Iss_Res where   Issue, Resolution LIKE" & text
[blue]
    Debug.Print(ad) [/blue][green]
    'What do you get in Immediste Window here?[/green]

    Dim cn As New SqlConnection(ConStr)
    Dim cn2 As SqlCommand = New SqlCommand(ad, cn)
    cn.Open()
    Dim sqlReader As SqlDataReader = cn2.ExecuteReader()
    ds = New DataSet
    dv = New DataView

Have fun.

---- Andy
 
Thanks, Andy, for the reply. I added the 'Debug.Print(ad)line, but debugging still displayed the same message on the "Dim sqlReader As SqlDataReader = cn2.ExecuteReader() line.
This is my first attempt at using vb.net. Thanks again!
 

I am new to .NET, too. But try to move your line where you open the connection:
Code:
[blue]
    cn.Open()[/blue]
    Dim cn As New SqlConnection(ConStr)
    Dim cn2 As SqlCommand = New SqlCommand(ad, cn)[green]
    'cn.Open()[/green]
    Dim sqlReader As SqlDataReader = cn2.ExecuteReader()
    ds = New DataSet
    dv = New DataView


Have fun.

---- Andy
 
It is your SQL structure;
try,
Code:
Dim ad As String = "Select * from Iss_Res where " & _
	"Issue LIKE '%" & Text & "%' OR Resolution LIKE '%" & Text & "%'"
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top