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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trying for days to compare variable with MySql statement in ASP.NET

Status
Not open for further replies.

SIMONI

IS-IT--Management
Aug 31, 2004
47
0
0
AU
Hi all,

I have a Myql stetment in in an ASP.NET page which I'm trying to compare a value (variable ).

This is the value and code that I need to compare (value is artist):

Dim dv2 As New Data.DataView


dv2 = CType(DS1.Select(DataSourceSelectArguments.Empty), Data.DataView)


Dim dr2 As Data.DataRowView = dv2(0)


Dim artistname As String = CStr(dr2("artist"))



This is the select statement in MySql:

selectcommand="SELECT topic, artist FROM news WHERE artist like "what do I need to put here" order by id desc limit 15"

My problem is that I don't know what to write after the LIKE in order to compare the value to the database?

I tried everything I could think of but nothing works.



Thanks

Simon


 
If you want to use LIKE, then you need the "%" symbol, either before or after or both when writing the statment.

So somehting like:
'This gets all artists with any chars BEFORE artistname
Where artist like "%" + artistname
OR
'This gets all artists with any chars AFTER artistname
Where artist like artistname + "%"
OR
'This gets all artists with any chars BEFORE or AFTER artistname
Where artist like "%" + artistname + "%"
 
Hi there,

Thanks for the response, I have tried that but i'm getting this error.

Parser Error
Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.

Parser Error Message: The server tag is not well formed.

Source Error:


Line 91: </asp:SqlDataSource>
Line 92:
Line 93: <asp:sqldatasource id="ds3" runat="server" providername="System.Data.Odbc" selectcommand="SELECT topic, artist FROM news WHERE artist like "%" + artistname + "%" order by id desc limit 15" >
Line 94: <selectparameters>
Line 95: <asp:querystringparameter name="id" querystringfield="id" type="string" />


Have i missed something?

Cheers,
Simon
 
I think you have to put your query in your code-behind because % is a special character...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top