Results 1 to 7 of 7

Thread: 2 questions on ado.net ...

  1. #1

    Thread Starter
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538

    2 questions on ado.net ...

    I'm finally writin my first .net project using ado.net. What I need to do is check whether any of the rows in my sql database table contain a username & password I pass to i.

    First off, is this the right way of going about this, then also, none of the examples in my wrox books list the set dataset = nothing equivalent, I guess the GAC does this for you now, but wondered if it's considered bad to put the setting to nothing options in with .net?

    VB Code:
    1. strSQL = "SELECT UserId, UserPassword FROM Users Where UserId ='" & _
    2.         strUserName & "' AND UserPassword='" & strUserPassword & "'"
    3.  
    4. objDAUsers = New SqlClient.SqlDataAdapter(strSQL, gstrDEVSQLSERVERCONN)
    5.  
    6. If Not (objDAUsers Is Nothing) Then
    7.     objDAUsers.Fill(objDSUserDetails)
    8.  
    9.     If Not (objDSUserDetails Is Nothing) Then
    10.  
    11.         Select Case objDSUserDetails.Tables(0).Rows.Count
    12.         Case 0
    13.             LoginPassedValidation = False
    14.         Case 1
    15.             LoginPassedValidation = True
    16.         End Select
    17.  
    18.     End If
    19. End If

    Thanks all!

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

  2. #2
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    If Not (objDSUserDetails Is Nothing) Then

    put instead : if objDSUserDetails.Lenght > 0 then

  3. #3

    Thread Starter
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538
    Right, just looked at this a bit more & I'll answer my own question 1 incase I need to come back to it. For a password check, it looks as through a forward, read-only datareader object is more efficeient to use.

    As for the second question, on the setting the connection & datareader/dataadapter objects to nothing, that one's still outstanding.

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

  4. #4
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    posted at the same time lol!

  5. #5

    Thread Starter
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538
    Was just gonna put that! lol
    Thanks for the suggestion there though!

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

  6. #6
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    As for setting things to nothing.
    The short answer:
    .NEt has a garbage collection thing it uses so you no longer need to set things to nothing, it pretty much is useless to. It seems wierd at first if you are used to vb6 but you get used to it.

    The long answer:
    http://www.vbforums.com/showthread.p...hreadid=211491

    Also in regards to the database query, it would be quicker to check if the count is greater than 0 and use an ExecuteScalar to just get back the count into a variable.

    VB Code:
    1. strSQL = "SELECT Count(*) FROM Users Where UserId ='" & _
    2.         strUserName & "' AND UserPassword='" & strUserPassword & "'"
    3. Dim cmd As New SqlCommand(strSQL, cnn)
    4. dim count as integer=cmd.ExecuteScalar()
    5. Select Case count
    6. Case 0
    7.      LoginPassedValidation = False
    8. Case 1
    9.      LoginPassedValidation = True
    10. End Select

  7. #7
    Hyperactive Member
    Join Date
    Mar 2002
    Location
    Dublin (Ireland)
    Posts
    304
    thanks for that last post, I'd been setting things to nothing basically because either I didn't fully understand or didn't trust garbage collection - probably both!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width