473,402 Members | 2,072 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,402 software developers and data experts.

Using SQL substring query in vb.net app

hello.
I have a webform form app in vb.Net that uses a SQL query. I am trying to use the substring function, but get the following error:
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Web.HttpException: A field or property with the name 'description' was not found on the selected datasource.

Source Error:
Line 68: daSearch.Fill(dsSearch, "SearchResults")
Line 69: dgrSearchResults.DataSource = dsSearch.Tables("searchresults").DefaultView
Line 70: dgrSearchResults.DataBind()
I know the field name description is correct, as I can remove the substring from the query and everything works...just my datagrid is too long.

Here is my SQL statement:
Dim daSearch As New SqlDataAdapter("select (substring('description',1,30)),idnum,station,iata num,inputdate,empname,status from tbTipDetail order by idnum", conn)
daSearch.Fill(dsSearch, "SearchResults")
dgrSearchResults.DataSource = dsSearch.Tables("searchresults").DefaultView
dgrSearchResults.DataBind()

Note: I get the same error with or without the dits around description.
I would appreciate any help or guidance you can offer.
Thank you.

--------------------------------
From: Michele Fondry

-----------------------
Posted by a user from .NET 247 (http://www.dotnet247.com/)

<Id>zZlUpy76YkmFj3tTqR+ZJQ==</Id>
Nov 21 '05 #1
2 6723
You are taking the substring of a constant there. Not the column named
"description"

I am guessing you are trying to avoid the problem of "description" being a
keyword? In which case, use [description] for the column name.

"Michele Fondry via .NET 247" <an*******@dotnet247.com> wrote in message
news:uq*************@TK2MSFTNGP12.phx.gbl...
hello.
I have a webform form app in vb.Net that uses a SQL query. I am trying to
use the substring function, but get the following error:
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.Web.HttpException: A field or property with the
name 'description' was not found on the selected datasource.

Source Error:
Line 68: daSearch.Fill(dsSearch, "SearchResults")
Line 69: dgrSearchResults.DataSource =
dsSearch.Tables("searchresults").DefaultView
Line 70: dgrSearchResults.DataBind()
I know the field name description is correct, as I can remove the
substring from the query and everything works...just my datagrid is too
long.

Here is my SQL statement:
Dim daSearch As New SqlDataAdapter("select
(substring('description',1,30)),idnum,station,iata num,inputdate,empname,status
from tbTipDetail order by idnum", conn)
daSearch.Fill(dsSearch, "SearchResults")
dgrSearchResults.DataSource =
dsSearch.Tables("searchresults").DefaultView
dgrSearchResults.DataBind()

Note: I get the same error with or without the dits around description.
I would appreciate any help or guidance you can offer.
Thank you.

--------------------------------
From: Michele Fondry

-----------------------
Posted by a user from .NET 247 (http://www.dotnet247.com/)

<Id>zZlUpy76YkmFj3tTqR+ZJQ==</Id>

Nov 21 '05 #2
change your SQL statment to add an alias for the decription field inside the
substring call. The way it's written here, the first column will be coming
back as an unknown (or server defined) column that is not 'description'. If
you add the capitalized parts I've added below, then the first 30 characters
of the description field will be returned as a computed column (also named
'description') and your call to find the field now named 'description'
should work.

select (substring('description',1,30)) AS
DESCRIPTION,idnum,station,iatanum,inputdate,empnam e,status from tbTipDetail
order by idnum

"Michele Fondry via .NET 247" <an*******@dotnet247.com> wrote in message
news:uq*************@TK2MSFTNGP12.phx.gbl...
hello.
I have a webform form app in vb.Net that uses a SQL query. I am trying to use the substring function, but get the following error: Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information
about the error and where it originated in the code.
Exception Details: System.Web.HttpException: A field or property with the name 'description' was not found on the selected datasource.
Source Error:
Line 68: daSearch.Fill(dsSearch, "SearchResults")
Line 69: dgrSearchResults.DataSource = dsSearch.Tables("searchresults").DefaultView Line 70: dgrSearchResults.DataBind()
I know the field name description is correct, as I can remove the substring from the query and everything works...just my datagrid is too
long.
Here is my SQL statement:
Dim daSearch As New SqlDataAdapter("select (substring('description',1,30)),idnum,station,iata num,inputdate,empname,stat
us from tbTipDetail order by idnum", conn) daSearch.Fill(dsSearch, "SearchResults")
dgrSearchResults.DataSource = dsSearch.Tables("searchresults").DefaultView dgrSearchResults.DataBind()

Note: I get the same error with or without the dits around description.
I would appreciate any help or guidance you can offer.
Thank you.

--------------------------------
From: Michele Fondry

-----------------------
Posted by a user from .NET 247 (http://www.dotnet247.com/)

<Id>zZlUpy76YkmFj3tTqR+ZJQ==</Id>

Nov 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: bdinmstig | last post by:
I refined my attempt a little further, and the following code does seem to work, however it has 2 major problems: 1. Very limited support for XPath features Basic paths are supported for...
19
by: Lauren Quantrell | last post by:
I have a stored procedure using Convert where the exact same Convert string works in the SELECT portion of the procedure but fails in the WHERE portion. The entire SP is listed below....
1
by: sysindex | last post by:
I am trying to find a way to dynamically retrieve the substring starting point of an nText field. My query looks something like SELECT ID,Substring(DOCTEXT,0,200) from mytable where DOCTEXT...
0
by: Gazi Mahmud | last post by:
I am trying to find a way to dynamically retrieve the substring starting point for an nText field. My query looks something like SELECT ID,Substring(DOCTEXT,0,200) from mytable where DOCTEXT...
7
by: Scott | last post by:
I need help to modify the code below to pass url variables from a framset. The click to run this will be in the mainFrame. This script works well in a non-frame page. Grabs the current url...
1
by: lion | last post by:
my Problem: a query string passed into a html page doesn't display correctly on a mac I am just using html and javascript (no ASP, PHP or server side scripting) This is the query string:...
6
by: Eduardo78 | last post by:
Ok, I have a Field that has a combination of letter C and a Number that increments by one. example: C1 C2 C3 C4 C5 C6
2
by: AtCor | last post by:
SELECT Sheet1$. AS , CASE Sheet1$. WHEN 'CSPP100A2344' THEN '0' END AS Extension, SUBSTRING(Sheet1$., 1, 4) AS , SUBSTRING(Sheet1$., 5, 8) AS , SUBSTRING(Sheet1$., 1, 4) ...
3
by: swetha123 | last post by:
hello, I don't know how to use cookies please help me in this I am using the dream weaver cs4 I designed the navigation bar to my page using dream weaver cs4 navigation bar contains...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.