Friday, March 19, 2010
I got two simple coldfusion tips for you.
1. Tip #1: See my previous post about Coldfusion issue when if you use SELECT * in your cfquery and then say you add a row to that table. That changes the query because you have now added another row for CF to grab. Apparently, CF doesn’t like that at all. It throws an error. All you have to do to fix the issue is Restart Coldfusion and then your site should be back up. I know it sucks, i shouldn’t have to restart CF when i add a new column to my table. Seems silly. And, I know SELECT * is not the correct or best way to write your query. You should always write out all of the columns and rows from all of the tables you are querying. The reason I am using SELECT * is because I want this query to work across multiple sites under different domains. I don’t want to have to go back and change every single query when i add a new column. That’s why i am doing it this way. One other added piece of information i should add here is that the error from coldfusion only occurs when you use cfqueryparam in your queries. CF must cache the query.
2. Tip #2: IF you have a Thankyou page that appears after you submit a form and you want to lock the page down be sure to add this little snippet of code at the top of your page. Say you have a form that accepts FirstName, LastName and EmailAddress. All of these are required. Pick one (or more) of the fields. At the very top of your page put this code:
<cfif NOT IsDefined(‘form.FirstName’)>
<cflocation url=“index.cfm” addtoken=“no”>
IF someone comes to the page and they try to see what you got without submitting your form they will get redirected to your homepage. Also, wrap the form.FirstName variable in single quotes. You need those. If you don’t use those, you will get a coldfusion error.
Hope this helps someone out there.
Saturday, March 06, 2010
Coldfusion Error: Value can not be converted to requested type.
Have you ever encountered this error? Well I did today. It wasn’t the first time either. In my SELECT statement I was using “SELECT * FROM tblname WHERE ID =
Seems coldfusion has a problem with this after I added a new column to the table i was querying.
The solution is when you write your SELECT statement you should not use *. Instead consider listing out each and every column name in your query. This will prevent the error from occuring, but if you ever add another column to your table you have to rewrite that query. That kinda sucks.
You can also remove the cfqueryparam from your SELECT statement and that will fix it too (actually this is what I think is the root of the problem because the query runs perfectly without cfqueryparam - it only breaks when i’m using cfqueryparam and i modify the table.)
Read this article on this error: