newbie questions

databases United States
  • 19 years ago

    hi all!


    how would i check if recordsets returned is empty or has no record?


    how would i search a particular record with a primary key in recordsets? (the search value will come from a variable or any value entered by the user on  a text box or any control. . .)


    how would i  know if the search is successful?


    any equivalent inlist() function in vb? e.g. if inlist(country,"Japan","Australia","US")


    in some programming language, i can do this in a case statement. . .


    do case
    case color="brown"
     ...
     ...
    case number="999"
     ...
     ...
    case name="Maria"
     ...
     ...
    endcase


    if any would come true then execute the succeding code. is this possible with the select case of vb?


    thanks a lot!

  • 19 years ago

    To check if a recordset is empty (or you have reached the end of it after calling .MoveNext), simply check the EOF property:
    Set objRS = objConn.Execute(theSQL)
    If objRS.EOF Then
      'no results
    End If


    for inlist(country,"Japan","Australia","US") , you have to loop through all the items in an array, and then check if the strings match. If you mean to check if a string is within another, use the Instr statement


    > if any would come true then execute the succeding code. is this possible with the select case of vb?
    I presume you mean that in, for example C++, if you omit break;, it will execute the next case statement. In VB it is not possible to replicate this behavour, unless you use a Goto statement (very ugly!)

  • 19 years ago

    VB Web said:

    Quote:
    do case
    case color="brown"
    ...
    ...
    case number="999"
    ...
    ...
    case name="Maria"
    ...
    ...
    endcase


    Actually using this Select case you can come close


    select case true
    case color is "brown"
    ...
    ...
    case number is 999
    ...
    ...
    case name is "Maria"
    ...
    ...
    end select
    it just evaluates the statements to see if they are true.

  • 19 years ago

    got them all except for the array thing. . . storing the values on an array before comparing a string variable if it exists in that array would be a tedious job to do.


    in visual foxpro: inlist(strCountry,"America","Japan","Australia") returns true (.T.) if it finds the expression in the set of expressions. i hope vb has this kind of function or any similar function that would work like this. . .


    thank you all!

  • 19 years ago

    To my knowledge, I don't believe VB has a function like that.

  • 19 years ago

    then i'll use instr()....


    thanks.

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“A computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are, in short, a perfect match” - Bill Bryson