Solved

SQL View Question

Posted on 2004-10-06
12
176 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
12 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
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…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

823 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