Wrox Programmer Forums
|
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 16th, 2008, 05:24 AM
Authorized User
 
Join Date: Feb 2007
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Default SQL LIKE Multiple Conditions

Im having some trouble using the SQL Like command with multiple conditions

where as the first line of code works with one condition the second one doesnt even thought it doesnt return any errors

Dim da As OleDbDataAdapter = New OleDbDataAdapter("SELECT * FROM chdetails WHERE chname LIKE '%" & txtFRname.Text & "%'", myConnection)

Dim da As OleDbDataAdapter = New OleDbDataAdapter("SELECT * FROM chdetails WHERE (chname LIKE '%" & txtFRname.Text & "%') AND (chsurname LIKE '%" & txtFRsname.Text & "%') AND (chDOB = '%" & txtFRdob.Text & "%')", myConnection)


Full Code is below

        Dim connString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data source =" & Server.MapPath("db2.mdb")
        Dim myConnection As OleDbConnection = New OleDbConnection
        myConnection.ConnectionString = connString
        ' create a data adapter

        Dim da As OleDbDataAdapter = New OleDbDataAdapter("SELECT * FROM chdetails WHERE (chname LIKE '%" & txtFRname.Text & "%') AND (chsurname LIKE '%" & txtFRsname.Text & "%') AND (chDOB = '%" & txtFRdob.Text & "%')", myConnection)

        ' create a new dataset

        Dim ds As DataSet = New DataSet
        ' fill dataset

        da.Fill(ds, "chdetails")
        ' Attach DataSet to DataGrid

        GridView1.DataSource = ds
        GridView1.DataBind()

        MultiView1.SetActiveView(child)

Where am I going wrong

 
Old April 16th, 2008, 06:24 AM
Authorized User
 
Join Date: Feb 2007
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I found it !

Dim da As OleDbDataAdapter = New OleDbDataAdapter("SELECT * FROM chdetails WHERE (chname LIKE '%" & txtFRname.Text & "%') AND (chsurname LIKE '%" & txtFRsname.Text & "%') AND (chDOB = '" & txtFRdob.Text & "')", myConnection)


instead of


Dim da As OleDbDataAdapter = New OleDbDataAdapter("SELECT * FROM chdetails WHERE (chname = '" & txtFRname.Text & "') AND (chsurname = '" & txtFRsname.Text & "') AND (chDOB = '" & txtFRdob.Text & "')", myConnection)


look very closely






Similar Threads
Thread Thread Starter Forum Replies Last Post
using multiple conditions in sql loader elygp Oracle 0 October 9th, 2008 10:21 PM
IIf Function - Multiple conditions carrie09 Access 2 June 13th, 2007 10:27 AM
Multiple conditions austinf XSLT 1 May 5th, 2006 02:55 AM
Multiple conditions austinf XSLT 1 May 5th, 2006 02:38 AM
Multiple If..Else conditions executed problem DavidGreen C# 2 March 16th, 2005 09:26 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.