Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

SQL View Question

Posted on 2004-10-06
12
Medium Priority
?
182 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

721 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