Wrox Programmer Forums
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old June 15th, 2007, 09:48 AM
Registered User
Join Date: Jun 2007
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default .NET query

I am trying to use a MS Access Database in an vb.aspx page.

I have written the following two queries.. but they are giving me errors which i am unable to fix.ANy help in this regard would be highly appreciated .

Query 1: Dim sSQL As String = "UPDATE AuthorTable" & _
                             " SET ID ='" & sID & "',Name = '" & sName & "',BookID ='" & sID & "',Date ='" & sDate & ""

It gives me the error: Syntax error in string in query expression '''.
I understand that there is probably a problem with the way I am ending the query. But I do not understand what would be the correct syntax. Please Help.

Query 2:
Dim sSQL As String = "SELECT COUNT(*)" & _
                              "FROM (" & _
                                "SELECT DISTINCT LastName" & _
                                 " FROM Authors" & _
                              "WHERE Month = '" & sMonth & "' AND ID = '" & sID & "')"

Error: Operator '&' is not defined for string "SELECT COUNT(*)FROM (SELECT DIST" and type 'ListItem'.

Would really appreciate a quick response.

Old June 15th, 2007, 06:56 PM
Wrox Author
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons

I hate doing SQL strings like this. Try this for your first query:

Dim sSQL as string = String.Format("Update AuthorTable SET ID ='{0}', Name = '{1}', BookID = '{0}', Date = '{2}'", sID, sName, sDate)

and i dont believe you SQL query is corret in the second account so try this instead

sSql = String.Format("Select count(*) from Authors where lastName in(SELECT DISTINCT lastName from authors where month='{0}' and id = '{1}')", sMonth, sID)

================================================== =========
Read this if you want to know how to get a correct reply for your question:
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
================================================== =========
Why can't Programmers, program??
================================================== =========
Old June 17th, 2007, 01:30 AM
Friend of Wrox
Join Date: Aug 2006
Posts: 109
Thanks: 0
Thanked 0 Times in 0 Posts

for the first error, check the data type of the fields, and make sure that ur string is right, as for the second one... can u really do anything like that in sql!!! as dparsons said, i really don't think you can do that mate :) .. although i do like the idea :)

Nothing is impossible. The impossible only takes longer. "Digital Fortress, Dan Brown"
Old June 19th, 2007, 03:36 PM
Registered User
Join Date: Jun 2007
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts

Thanks.. Let me try what you suggested.
well I was able to run the second query in access database and also as a query in a table adapter. So its correct though the problem now is that I want to use the count to decide the number of columns that the table( on the web page) will have.
Is there a way I can include a table adapter in aspx page, use the count variable and include that in a for loop creating rows determined on this count?

i.e for i = 1 to count
{ build a row
and display the last name as a label there)

Similar Threads
Thread Thread Starter Forum Replies Last Post
Query for ScreenScraping Tech in .NET visit2siva ASP.NET 1.x and 2.0 Application Design 1 December 15th, 2005 12:42 PM
Query for ScreenScraping Tech in .NET visit2siva C# 1 December 7th, 2005 09:44 AM
how to query 2 tables in asp.net method ASP.NET 1.0 and 1.1 Basics 3 March 18th, 2005 04:35 PM
.net Query sindhoor .NET Web Services 1 October 20th, 2003 12:22 PM
.NET XPath query not coming out right perropicante C# 0 June 15th, 2003 10:53 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.