i have a listview with items and i can check some category, some item details, or returns a null image link a load a default image but i miss something because command is wrong
SELECT IIF(ISNULL(Atleta.url_imagem), 'no_photo.jpg', Atleta.url_imagem) as URLImagem, Atleta.id, Atleta.nome, Categoria.nome AS Expr1, Atleta.id_categoria FROM Atleta INNER JOIN Categoria ON Atleta.id_categoria = Categoria.id WHERE ((? = 0) or (Atleta.id = ?)) and ((? = 0) or (Atleta.id_categoria = ?)) order by Atleta.nome
SELECT ISNULL(Atleta.url_imagem,'no_photo.jpg') as urlimagem, Atleta.id, Atleta.id_categoria, Categoria.nome AS Expr1, Atleta.id_categoria
FROM Atleta INNER JOIN Categoria ON Atleta.id_categoria = Categoria.id WHERE
((? = 0) or (Atleta.id = ?)) and ((? = 0) or (Atleta.id_categoria = ?))
order by Atleta.nome
SELECT ISNULL(Atleta.url_imagem,'no_photo.jpg') as urlimagem, Atleta.id, Atleta.id_categoria, Categoria.nome AS Expr1, Atleta.id_categoria
FROM Atleta INNER JOIN Categoria ON Atleta.id_categoria = Categoria.id WHERE
((? = 0) or (Atleta.id = ?)) and ((? = 0) or (Atleta.id_categoria = ?))
order by Atleta.nome
troika
Member
14 Points
191 Posts
check if string is null in sql
Jan 26, 2013 12:54 AM|LINK
alankarp
Contributor
2042 Points
345 Posts
Re: check if string is null in sql
Jan 26, 2013 04:36 AM|LINK
try this
No need to use IIF
Profile
oned_gk
All-Star
30917 Points
6327 Posts
Re: check if string is null in sql
Jan 26, 2013 05:45 AM|LINK
You can simply replace the null image in ASP.NET page
<asp:Image ID="Image1" runat="server" ImageUrl='<%# isdbnull(Eval("url_imagem")) ? "no_photo.jpg" : Eval("url_imagem") %>' />troika
Member
14 Points
191 Posts
Re: check if string is null in sql
Jan 26, 2013 09:38 AM|LINK
it givies me syntax error near ?
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: check if string is null in sql
Jan 28, 2013 12:36 AM|LINK
Hi,
Please use your suitable field or column name propertly instead of "?", because answerer doesn't know you real columnName.
troika
Member
14 Points
191 Posts
Re: check if string is null in sql
Jan 30, 2013 09:42 AM|LINK
what i need is a querystring thats why i use ?
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: check if string is null in sql
Feb 01, 2013 12:48 AM|LINK
Please use parameter token and QueryStringParameter, and here's a sample:
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.sqldatasource.aspx
troika
Member
14 Points
191 Posts
Re: check if string is null in sql
Feb 07, 2013 01:30 PM|LINK
i'm using this command to check if is dbnull , but i also need to check if its empty... how can i do that here in image and link eval's
and also this is not loading the default no_photo image...
<a href='<%# Eval("photo") == DBNull.Value ? "/images/no_photo.png" : Eval("photo") %>' rel="lightbox[on]" title="+ <a href='<%# Eval("Link") %>'>Info</a>"><asp:Image id="img" runat="server" ImageUrl='<%#Eval("photo", "~/images/uploads/{0}") %>' /> </a>Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: check if string is null in sql
Feb 08, 2013 12:08 AM|LINK
Hi,
for multiple checkings, I think you can just write down a function to cope with this:
<a href='<%# MyFunc(Eval("photo"))%>And thenprotected string MyFunc(object obj){
if(obj==null || obj==DbNull.Value)
return something;
else if (obj.ToString().Trim()=="")
return something;
else
return obj.ToString();
}