Wrox Programmer Forums
|
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 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 February 16th, 2007, 01:57 PM
Authorized User
 
Join Date: Sep 2006
Posts: 82
Thanks: 0
Thanked 0 Times in 0 Posts
Default If Statement Query

Hi,

I am working on an if statement that I want to check if a unique value , which is stored in the session object, is already inserted into a database's table. Thus the coding would be something like :

* Connect to database and table

* If unique value = session "(Value") update the database

 Else insert this value into the table

Now within asp.net I assume you would use the select command with an sql statement to do this, but how exactly should I do this ?

e.g Dim queryString As String = "SELECT [tblxxx].[value] FROM [tblxxx]"

             If [tblxxx].[value] = Session("value") ......

However this results in an error stating "Name [tblxxx] is not declared"....

Any examples would help ? I'm using asp.net 1.1 with vb.net and connecting to an access database.

Thanks,


 
Old February 16th, 2007, 02:04 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
Default

This is all relative to what you are placing your data in (Datareader, datatable, dataset), but its the same concept for all of them.

I will assume that you are placing the resultset in a datatable

If Convert.ToString(dt.rows(0).item("columnName")) = Convert.ToString(Session("value")) then
'do something
End if

Where dt is your DataTable object.

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from planoie's profile^^
^^Modified text taken from gbianchi profile^^
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html
 
Old February 17th, 2007, 06:52 AM
Authorized User
 
Join Date: Sep 2006
Posts: 82
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks,

I've developed some code as below but suspect the first part of the SQL statement i.e. the bit that checks if there is a CARTID already inserted, is not quite right. However no errors are displayed. Basically I want to say :

Look within the table and if CartID equals zero, i.e. it does not exist in the table, then insert values into the table.

Here's the code - any ideas :

Code:
 Dim strSQL As String

strSQL = "SELECT [tblTotal].[intCartID] FROM [tblTotal] WHERE ([tblTotal].[intCartID] = 0) "& _
"VALUES (@intCartID, @curGrandTotal)"
 
Old February 18th, 2007, 12:04 AM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Ok a couple of things, first what is your VALUES statement for?? I am unfamiliar with a Values list being in a SELECT statement?

Unfortunatley your using access else I would suggest just writing a stored procedure to handle this and keep your code clean. I have a question though, wont your SELECT statement ALWAYS insert a new row? Your where clause doesnt evaluate against a variable, it always will evaluate against 0 and, by your explination, 0 means that the row doesn't exist hence a new row would be inserted.

In any case I would do something like SELECT Count(intCartID) as cartID from table where intcartid = 0

If Convert.ToInt32(dt.rows(0).item("cartID")) = n then
'execute insert statement
end if

Where n in the above statement will be how many rows are returned where the cartID = 0. (I assume it would be 0 as well but am not sure.)

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from planoie's profile^^
^^Modified text taken from gbianchi profile^^
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html

Discussion:
http://p2p.wrox.com/topic.asp?TOPIC_ID=56429





Similar Threads
Thread Thread Starter Forum Replies Last Post
IF statement in SQL Pass Through Query Coby Access VBA 3 February 15th, 2008 09:24 AM
query statement larry67 Access 1 March 8th, 2007 12:41 PM
verify my query statement gilgalbiblewheel Classic ASP Databases 2 July 7th, 2005 01:39 PM
how to remove the query statement? gilgalbiblewheel Classic ASP Databases 8 September 11th, 2004 11:10 AM
SQL statement for query vickriz Access 4 September 24th, 2003 10:16 PM





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