Showing posts with label page. Show all posts
Showing posts with label page. Show all posts

Tuesday, March 27, 2012

Default Image URL in DataList control!

Hey,

I have two questions:

1- In my page there should be a list of all system users, each of them may have an image or may not.

So what I need to do is how to make the next SQL query return a default ImageURL - e.g. "noAvator.jpg" - in case of null image value?

SELECT UserName , image, notes
FROM Members

2- When I try to write an image url in the SQL Server 2005 Management Studio - as "images/noAvator.jpg" or any other name - it always through me this error messagebox:

The changed value is not recignized as valid.
.NET Framework Data Type: Byte[]
Error Message: You can not use the Result pane to set this Field data to value other than NULL.

Why is that? is there a problem with the format of typing the image url?

I appreciate your help!

I'm not sure why you're receiving that error, but how about doing this within your ASPX page instead? If you are displaying your users in some type of GridView, then simply modify the data-binding expression for your image like so:

<asp:imageid="Image1"runat="server"imageurl='<%# (Eval("image") == DBNull.Value) ? "images/noAvator.jpg" : Eval("image") %>'/>

|||

ecbruck:

I'm not sure why you're receiving that error, but how about doing this within your ASPX page instead? If you are displaying your users in some type of GridView, then simply modify the data-binding expression for your image like so:

<asp:imageid="Image1"runat="server"imageurl='<%# (Eval("image") == DBNull.Value) ? "images/noAvator.jpg" : Eval("image") %>'/>

Hiecbruck,

Thanks for you reply,
Just for records, can you give me an example of image type format?

|||

You really shouldn't be using image as a column name, especially not quoted since image is a reserved datatype. Considering that the error message is complaining of trying to convert to a byte array, this leads me to believe that something is getting confused and thinking that you are talking about an actual image. Assuming the image column is of a varchar, or nvarchar datatype, then you can also change your query to be:

SELECT ISNULL(MyColumnNotNamedImage,'images/noAvator.jpg') FROM ...

|||

Motley:

You really shouldn't be using image as a column name, especially not quoted since image is a reserved datatype. Considering that the error message is complaining of trying to convert to a byte array, this leads me to believe that something is getting confused and thinking that you are talking about an actual image. Assuming the image column is of a varchar, or nvarchar datatype, then you can also change your query to be:

SELECT ISNULL(MyColumnNotNamedImage,'images/noAvator.jpg') FROM ...

Thanks alot, Motley!

Friday, February 17, 2012

debug stored procedure

I created a stored procedure that is referenced by a SQLDataSource& DetailView on a web page. I tested the stored procedure in QueryAnalyzer & everyting looks good.
When I get to the page to display the detailview, nothing is displayed.I ran SQL Profiler, to see what was happening & the storedprocedure isn't being called.
I checked & rechecked the references to the SQLDataSource & even tested them in the configuration wizard.
I replaced the stored procedure with the query & it worked, except I had to 'hardcode' the variable values.

The stored procedure does return error results when they occur - how can I intercept them?

How can I determine what is happening with this stored procedure? Is there a way to trace it other than with SQL Profiler?

Thanks in advance.

OldSamIf your stored proc works fine in Query Analyzer and not from your app unless the parameters are hardcoded => your values from the app are not being properly communicated with the stored proc. You could do a response.write of the values you are passing to see whats being passed.|||You are correct. I found it just before your post arrived - one of my nvarchar fields was NULL.
I still wish there were a better way to see these values in debug mode. I suspect there is; I just don't know how to get to it.

Thanks

OldSam|||

If you have VS 2005 you can create a Database Project and supposedly you can debug stored procs. I havent yet done that though.