473,396 Members | 1,771 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,396 software developers and data experts.

Code running out of order

I've got an app I'm writing that has logic like this:

1. Check the database. If any of the items on List X are already in there,
post an error stating which items are duplicates.

2. Add the non-duplicate items to the database.

Unfortunately, it's checking the steps in reverse order for some reason, so
that it adds the items to the db, and then reports all of them as
duplicates (because now they are in the db). Here's my relevant code (SQL
function not included, since it's not relevant... when I run the SQL
function by itself, it operates fine):

Private Sub btnQuickStart_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles btnQuickStart.Click
[...]
CheckExisting(ProductList)
AddNewItems(ProductList)
End Sub

Private Sub CheckExisting(ByVal ProductList As String)
Dim strSQL As String = "SELECT * FROM fnSearchBySuite(" &
ProductList & ") WHERE SuiteCount = 1 AND SuiteID IN (SELECT SuiteID FROM
tblItems WHERE PresentationID = " & Request.QueryString("ID") & ")"
Dim Cmd As New SqlCommand(strSQL, cnSalesWiz)
Dim DA As New SqlDataAdapter(Cmd)
Dim DT As New DataTable
Dim DR As DataRow
DA.Fill(DT)
If DT.Rows.Count > 0 Then
DuplicateResults.InnerHtml = ""
DuplicateResults.InnerHtml &= "<span class=MainHeader>Duplicate
Items Detected</span>"
DuplicateResults.InnerHtml &= "The following groups were
already in your presentation, and have been ignored:<br><br>"
For Each DR In DT.Rows
DuplicateResults.InnerHtml &= DR("SuiteName") & "<br>"
Next
DuplicateResults.InnerHtml &= "<br><br>"
DuplicateResults.Visible = True
End If
End Sub

Private Sub AddNewItems(ByVal ProductList As String)
Dim strSQL As String = "SELECT * FROM fnSearchBySuite(" &
ProductList & ") WHERE SuiteCount = 1 and SuiteID NOT IN (SELECT SuiteID
FROM tblItems WHERE PresentationID = " & Request.QueryString("ID") & ")"
Dim Cmd As New SqlCommand(strSQL, cnSalesWiz)
Dim DA As New SqlDataAdapter(Cmd)
Dim DT As New DataTable
Dim DR As DataRow
DA.Fill(DT)
If DT.Rows.Count > 0 Then
AddedToPresentation.InnerHtml = ""
AddedToPresentation.InnerHtml &= "The following groups have
been added to your presentation:<br><br>"
Dim cmdAddProduct As New SqlCommand
With cmdAddProduct
.Connection = cnSalesWiz
.CommandType = CommandType.StoredProcedure
.Parameters.Add("@PresentationID", SqlDbType.Int)
.Parameters.Add("@SuiteID", SqlDbType.Int)
End With
For Each DR In DT.Rows
With cmdAddProduct
.CommandText = "prAssignProduct"
.Parameters("@PresentationID").Value = CInt
(Request.QueryString("ID"))
.Parameters("@SuiteID").Value = CInt(DR("SuiteID"))
.ExecuteNonQuery()
End With
AddedToPresentation.InnerHtml &= DR("SuiteName") & "<br>"
Next
AddedToPresentation.InnerHtml &= "<br><br>"
AddedToPresentation.Visible = True
End If
End Sub
Nov 21 '05 #1
2 1287
Scott McNair <sc**********@sfmco.takethispartout.com> wrote in
news:Xn*******************@207.46.248.16:
I've got an app I'm writing that has logic like this:

1. Check the database. If any of the items on List X are already in
there, post an error stating which items are duplicates.

2. Add the non-duplicate items to the database.


I've tracked the problem down to the part where it writes the data back to
the database... if I rem out the actual line where the record is inserted,
everything works fine.
Nov 21 '05 #2
Scott McNair <sc**********@sfmco.takethispartout.com> wrote in
news:Xn*******************@207.46.248.16:
I've tracked the problem down to the part where it writes the data
back to the database... if I rem out the actual line where the record
is inserted, everything works fine.


However, that doesn't fix my actual problem... I've rewritten the code a
couple of different ways, and it still does the same thing. Here's a
nutshell version of my code as it's currently written (note: logic is
slightly different from my first post, since I've been fiddling with the
code to try to make it work):

Pull Data From Database Where Data In ThisList
For Each Item in ThisList
If Item = Duplicate Then
Report It's a Dupe
Else
Add It to the Database
End If
Next

However, after it adds the item it reports that the item is in the
database. If I take out the part where it actually writes the data, it
works fine (except for the fact that no data is being written of course).
It's almost as though it's running both parts at once... hard to explain.
Nov 21 '05 #3

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

Similar topics

20
by: Xenophobe | last post by:
I have successfully converted the ASP code included in the following article to PHP: http://www.4guysfromrolla.com/webtech/040100-1.shtml As described the high and low latitudes and longitudes...
1
by: Tung Wai Yip | last post by:
I've build the following utility. It works so far but I want to make sure I'm doing the right thing. I am running Python 2.3 on windows 2000. def execute(cmd): """ execute cmd in sub-process,...
242
by: James Cameron | last post by:
Hi I'm developing a program and the client is worried about future reuse of the code. Say 5, 10, 15 years down the road. This will be a major factor in selecting the development language. Any...
2
by: \ | last post by:
Hi...I found your group on the search engine...First you have to know that I'm on a webtv unit.....I am really desperate.. I'm not much on tech terms as most of my pages are found and reworked...
2
by: Kavitha Rao | last post by:
Hi, I am getting the following errors while trying to run this snippet in Microsoft Visual C++.Can't seem to print the crc value stored. /* +++Date last modified: 05-Jul-1997 */ /* Crc - 32...
2
by: Bas de Laat | last post by:
I'm trying to fix a running (12 month rolling) sum on a large table (over 50.000) record. I found already several good advices. First I Tried it with an Subquery But for large tables it takes to...
15
by: Cheryl Langdon | last post by:
Hello everyone, This is my first attempt at getting help in this manner. Please forgive me if this is an inappropriate request. I suddenly find myself in urgent need of instruction on how to...
0
by: murat-mur | last post by:
Hi all, Environment: My PC: MS Windows 2000 pro, DB2 Connect Client 7.1 Gateway: MS Windows 2000 server. DB2 Connect EE. DB2 z/OS V7.1 z/OS 1.6 php 5.1.2 is running on my PC. the below...
3
by: mochatrpl | last post by:
I am looking for a way to make a query / report display the running average for total dollars. I have already set up a query to provide totals dollars per day from which a report graphly shows...
3
by: Hazza | last post by:
Hi, I am using PHP and mysql to create a website. I am fairly new to PHP, and thus am grateful to anyone who helps! Firstly I am running a homepage, that displays additional content if a user...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.