Solved

Find an item by non-key column in dataset

Posted on 2004-10-11
3
233 Views
Last Modified: 2010-04-23
Hi, i have an established connection, a valid dataset and a working dataadapter. There is a table and few columns in it. Let me define

dataset: ds
dataadapter: daTable
table: Table
columns in table: itemNo, itemName, UPCcode
key column: itemNo

i need to find out an itemNo by UPCcode value using dataset, not direct connection to database
what should my command look like?

Thanks in advance
0
Comment
Question by:UnFiRe
[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
  • 2
3 Comments
 
LVL 2

Accepted Solution

by:
GohdanTheMoblin earned 500 total points
ID: 12281122
Try this:      

        Dim dr As DataRow() = ds.Tables("Table").Select("UPCcode = " & value)
        If dr.Length > 0 Then
            Dim itemNo As Integer = CInt(dr(0)("itemNo"))
        End If

Assuming itemNo is an Integer.
0
 
LVL 1

Author Comment

by:UnFiRe
ID: 12287668
Hi,
This expression worked to some extent. Thanks a lot for it
However, there is some problem.
I have another column called "OLDITEM" in the same table
It is a text field. In fact all fields are text fields because itemNo and OLDITEM and UPCCode can include letters.
My modified expression of a function to define itemNo by either upc or olditem looks like that:

*******************
Public Function itemNoBy(ByVal byWhat As String, ByVal num As String) As String
        Dim itemNo As String
        Dim dr As DataRow()
       
        'parameters passed to this function are either "upc" or "old"
        Select Case byWhat
            Case "upc"
                dr = myRef.dsJB.Itemweb.Select("UPCCODE = " & num)
            Case "old"
                dr = myRef.dsJB.Itemweb.Select("OLDITEM = " & num)
        End Select

        If dr.Length > 0 Then
            itemNo = dr(0)("itemNo").ToString
        Else
            itemNo = "Not Found"
        End If

        Return itemNo
End Function

***********************

Now, when i pass upc - everything works out perfect, however, when i pass old - i get this error. Why would i get it? All fields have absolutely the same properties, they are all text fields and in my dataset they are all String fields.

An unhandled exception of type 'System.Data.EvaluateException' occurred in system.data.dll

Additional information: Cannot perform '=' operation on System.String and System.Int32.
0
 
LVL 2

Expert Comment

by:GohdanTheMoblin
ID: 12308720
Oh, I think I see what's happening.  Suppose num is 555.

When you construct the statement
"UPCCODE = " & num

it is constructed as
"UPCCODE = 555"

which is a numeric search, not a string search.  Try changing those statements to
"UPCCODE = '" & num & "'"

It's tough to see, but there are single quotes in there.
0

Featured Post

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Find date of 2nd Thursday of each month 3 45
Format Transaction Number 19 49
Need to Interpret Json in Vb.net ( .net 3.5  framework) 11 51
Check only one toolstripmenu item 12 62
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…
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…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

739 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