Last post Jul 02, 2010 01:41 PM by SynergyNT
Jun 25, 2010 03:54 PM|donpisci|LINK
I'm pulling a description from my database, but for one page, only want 100 characters to be retrieved. I've tried using the LEFT function but it didn't work ( I used the following query: Select i.filepath, p.header, LEFT('p.description', 100))
Is this something I should be doing within the SQL statement, or would you recommend doing this within my c# code?
Thanks in advance!
Jun 25, 2010 04:31 PM|SynergyNT|LINK
Try removing the single quotes around your field name in the LEFT function. The single quotes should be used if you are telling the LEFT function to evaluate that exact string of characters. You could also try using the SUBSTRING function as below...
SUBSTRING(p.description, FROM 1, FOR 100)
Jun 26, 2010 07:36 AM|donpisci|LINK
Thanks for that- I tried the substring function but got the following error:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM 1, FOR 100), p.priceFROM images i, property p, thumbnail t
My code is here:
SUBSTRING(p.description,FROM 1, FOR 100),
I also tried removing the quotes for the LEFT function, but got the following, which is weird as it works without the LEFT function:
System.Data.DataRowView' does not contain a property with the name 'description'
Jun 27, 2010 01:53 AM|SynergyNT|LINK
My apologies. My example used incorrect syntax.
SUBSTRING(p.description FROM 1 FOR 100)
The commas are used if you do not use the FROM and FOR keywords.
Jun 27, 2010 06:44 AM|donpisci|LINK
Thanks for that Synergy... I'm no longer getting the syntax error
However, I am now getting the following error:
DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'description'.Thanks for
Which is weird as it all works without the SUBSTRING function, and the only thing that has changed is the substring addition. Do I have to rename anything?
Jun 27, 2010 04:25 PM|SynergyNT|LINK
You shouldn't have to rename it. I just ran this query on a table of my own. This query worked with my table.
select substring(u.username from 2 for 1) from tbl_users u;
Do you have access to test your query directly on the server? I'm wondering if it may be something with your data control.
Jul 02, 2010 06:26 AM|donpisci|LINK
Apologies for not getting back to you sooner.
I've tried running the query ondirectly on the server, but to no avail. I've also changed my page so that I use the codebehind, as opposed to using an SQLDatasource, but still no luck.
Jul 02, 2010 10:16 AM|SynergyNT|LINK
So what happened when you ran the query directly on the server? Did it pull the data you expected or did it throw an error?
Jul 02, 2010 10:49 AM|donpisci|LINK
Yes, I got the error about there not being a property called 'description'. Very frustrating!
Jul 02, 2010 11:15 AM|vishwaraj1|LINK
declare @desc nvarchar(500)
set @desc='123select RIGHT(description,150) as description from H1_PostListing select LEFT(description,150) as description from H1_PostListing987'
select Left(@desc,50) as description
after changes it will be like
select column1,column2, Left(t.description,100) as description from tablename t
Jul 02, 2010 01:41 PM|SynergyNT|LINK
I'm sorry, but can you copy the exact error you get when you run the query directly through MySQL? I'm still trying to figure out where the problem lies. If it is your SQL statement or something with the data control on your page.