|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Using SQL substring query in vb.net appI 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,iatanum,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> 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. Show quoteHide quote "Michele Fondry via .NET 247" <anonym***@dotnet247.com> wrote in message news:uqGGV6WNFHA.244@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,iatanum,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> 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,empname,status from tbTipDetail order by idnum "Michele Fondry via .NET 247" <anonym***@dotnet247.com> wrote in message use the substring function, but get the following error:news:uqGGV6WNFHA.244@TK2MSFTNGP12.phx.gbl... > hello. > I have a webform form app in vb.Net that uses a SQL query. I am trying to > Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more informationabout the error and where it originated in the code. > name 'description' was not found on the selected datasource.> Exception Details: System.Web.HttpException: A field or property with the > dsSearch.Tables("searchresults").DefaultView> Source Error: > > > Line 68: daSearch.Fill(dsSearch, "SearchResults") > Line 69: dgrSearchResults.DataSource = > Line 70: dgrSearchResults.DataBind() substring from the query and everything works...just my datagrid is too> > > I know the field name description is correct, as I can remove the long. > (substring('description',1,30)),idnum,station,iatanum,inputdate,empname,stat> Here is my SQL statement: > Dim daSearch As New SqlDataAdapter("select us from tbTipDetail order by idnum", conn) > daSearch.Fill(dsSearch, "SearchResults") dsSearch.Tables("searchresults").DefaultView> dgrSearchResults.DataSource = Show quoteHide quote > 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>
Mixing VB variables with standard text to output text file
Refresh DataSet - please Help Me :-( Get Variable Out of Arraylist ReInstantiate an Object? Advice needed How can I determine WHICH exception I got in my CATCH? using StringBuilder class for concatenation? foxpro table hosed up when called 2nd time from VB.net Creating array on the fly as a parameter to a subroutine? SaveFileDialog |
|||||||||||||||||||||||