Solved

SQL View Question

Posted on 2004-10-06
12
175 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
 
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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

705 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now