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

x
?
Solved

Find an item by non-key column in dataset

Posted on 2004-10-11
3
Medium Priority
?
236 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 1500 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

704 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