Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

SQL View Question

Posted on 2004-10-06
12
Medium Priority
?
183 Views
Last Modified: 2010-08-05
Hi,

I have a view in a SQL Database (Sales) called sales_actuals_AB.  I created a SQL Connection (connSales), SQL Data Adapter (daPrevBudget), and Data Set (DsPrevBudget) visually.  I then added a primary key to the dataset (values SalesID and ItemSetID).  I can preview the data fine visually (by right clicking on the data adapter and selecting preview data).  When I run the below code...

************************************************************************
        Dim drPrev As DataRow
        Dim keys(1) As Object

        connSales.Open()
        daPrevBudget.Fill(DsPrevBudget)

        keys(1) = "1001AC    " 'lstSalesman.SelectedValue
        keys(0) = "AS005-1             " 'lstItem.SelectedItem

        drPrev = DsPrevBudget.Tables("sales_actuals_AB").Rows.Find(keys)

        If Not dr Is Nothing Then
            txtUnit1E.Text = drPrev("QTY_01")
            txtUnit1A.Text = drPrev("Aqty_01")
            txtDollar1A.Text = drPrev("Adol_01")
        Else
            txtUnit1E.Text = DsPrevBudget.Tables("sales_actuals_AB").Rows.Count()
        End If

        connSales.Close()
************************************************************************

The datarow always returns nothing.  I am not sure why because I copied values EXACTLY as shown in the SQL view.  Obvisouly I would like to not use static values in the following lines. (I commented out the dymanic value).

************************************************************************
        keys(1) = "1001AC    " 'lstSalesman.SelectedValue
        keys(0) = "AS005-1             " 'lstItem.SelectedItem
************************************************************************

The following code...

************************************************************************
txtUnit1E.Text = DsPrevBudget.Tables("sales_actuals_AB").Rows.Count()
************************************************************************

always returns the correct number of rows (400 something).

Does anyone have any ideas?  

NeoTek
0
Comment
Question by:NeoTek
  • 5
  • 5
11 Comments
 
LVL 25

Expert Comment

by:RonaldBiemans
ID: 12237405
does this work (without the spaces)

keys(1) = "1001AC"
0
 
LVL 1

Author Comment

by:NeoTek
ID: 12237529
No.  I've tried with and without the spaces.  I've also tried different SalesIDs and ItemSetIDs.
0
 
LVL 25

Expert Comment

by:RonaldBiemans
ID: 12237576
In your table in which order are the primary keys defined, because maybe it is the otherway around like

keys(0) = "1001AC    "
keys(1) = "AS005-1             "
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 1

Author Comment

by:NeoTek
ID: 12237993
Nope.  I have tried both ways.  In my DataSet and View SalesID appears on the top of the list.  Any other ideas?
0
 
LVL 25

Expert Comment

by:RonaldBiemans
ID: 12238181
Just a test, if you do this

       keys(0) = "1001AC    " 'salesID
       keys(1) = "AS005-1             " 'itemsetid

dim dv as new dataview = DsPrevBudget.Tables("sales_actuals_AB").defaultview
dv.sort = "SalesID,ItemSetID"
dim x as integer = dv.find(keys)

does x return a value > 0 ?
0
 
LVL 25

Expert Comment

by:RonaldBiemans
ID: 12238310
if that doesn't work try this

keys(0) = DsPrevBudget.Tables("sales_actuals_AB").rows(1).item("SalesID")
keys(1) = DsPrevBudget.Tables("sales_actuals_AB").rows(1).item("ItemSetID")


dim dv as new dataview = DsPrevBudget.Tables("sales_actuals_AB").defaultview
dv.sort = "SalesID,ItemSetID"
dim x as integer = dv.find(keys)

does x return a value >= 0 ?
0
 
LVL 1

Author Comment

by:NeoTek
ID: 12239845
When I run this...

        keys(0) = "1001AC" 'salesID
        keys(1) = "AS005-1" 'itemsetid

        Dim dv As New DataView(DsPrevBudget.Tables("sales_actuals_AB"))
        dv.Sort = "SalesID,ItemSetID"
        Dim x As Integer = dv.Find(keys)
        txtUnit1E.Text = x

I get 16.  But there is only one record that should return.  There are 8 records with 1001AC, and of his 8 one is AS005-1.  When I change the item to lifestyle, I get 19, but once again there are 8 records with 1001ac and one which is lifestyle.  Any ideas?
0
 
LVL 1

Author Comment

by:NeoTek
ID: 12241179
Any ideas?
0
 
LVL 1

Author Comment

by:NeoTek
ID: 12241275
Oh man, I am such a moron.  This code...

************************************************************************
        Dim drPrev As DataRow
        Dim keys(1) As Object

        connSales.Open()
        daPrevBudget.Fill(DsPrevBudget)

        keys(1) = "1001AC    " 'lstSalesman.SelectedValue
        keys(0) = "AS005-1             " 'lstItem.SelectedItem

        drPrev = DsPrevBudget.Tables("sales_actuals_AB").Rows.Find(keys)

        If Not dr Is Nothing Then
            txtUnit1E.Text = drPrev("QTY_01")
            txtUnit1A.Text = drPrev("Aqty_01")
            txtDollar1A.Text = drPrev("Adol_01")
        Else
            txtUnit1E.Text = DsPrevBudget.Tables("sales_actuals_AB").Rows.Count()
        End If

        connSales.Close()
************************************************************************

...is wrong.  The line...

If Not dr Is Nothing Then

..should be...

If Not drPrev Is Nothing Then

I feel really, really dumb...

NeoTek

0
 
LVL 25

Expert Comment

by:RonaldBiemans
ID: 12246186
Hi neotek, Then we are both morons because I also missed that completly :-), just get your points refunded.
0
 
LVL 2

Accepted Solution

by:
Lunchy earned 0 total points
ID: 12271154
Closed, 500 points refunded.
Lunchy
Friendly Neighbourhood Community Support Admin
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

876 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question