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
Solved

SQL View Question

Posted on 2004-10-06
12
177 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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

789 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