User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the VB.NET section within the Software Development category of DaniWeb, a massive community of 427,100 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,289 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our VB.NET advertiser: Programming Forums
Views: 366 | Replies: 3
Reply
Join Date: Jul 2008
Posts: 26
Reputation: Bill Purkins is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 1
Bill Purkins Bill Purkins is offline Offline
Light Poster

How to retrieve rowcount as variable from query

  #1  
Jul 19th, 2008
Using VB 2008, I am stumped. I have a fillby and getdataby table adapter query that does a SELECT COUNT from FILENAME where fieldname = textbox and I want to use the number of rows returned, but can't figure out how to reference it. This seems so simple, but I have been Googling this for nearly two hours and can't figure it out. Any help would be appreciated.
Thanks,
Bill P.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Nov 2007
Location: � Jogja �
Posts: 2,585
Reputation: Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light 
Rep Power: 11
Solved Threads: 235
Jx_Man's Avatar
Jx_Man Jx_Man is offline Offline
Posting Maven

Re: How to retrieve rowcount as variable from query

  #2  
Jul 19th, 2008
  1. "Select Count (*) from FILENAME where fieldname = '" & Trim(textbox.text) & "' "
Last edited by Jx_Man : Jul 19th, 2008 at 12:39 pm.
Never tried = Never Know
So, Please do something before post your thread.
* PM Asking will be ignored *
Reply With Quote  
Join Date: Jul 2008
Posts: 26
Reputation: Bill Purkins is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 1
Bill Purkins Bill Purkins is offline Offline
Light Poster

Re: How to retrieve rowcount as variable from query

  #3  
Jul 19th, 2008
Thanks for your reply. That is basically what I am doing. My problem is that I want to use the value of COUNT in code, i.e.

if count = 0 then
' do something
end if

How do I refence it?

Thanks again,
Bill P.
Reply With Quote  
Join Date: Nov 2007
Location: � Jogja �
Posts: 2,585
Reputation: Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light 
Rep Power: 11
Solved Threads: 235
Jx_Man's Avatar
Jx_Man Jx_Man is offline Offline
Posting Maven

Re: How to retrieve rowcount as variable from query

  #4  
Jul 19th, 2008
im used sql server (you can modified this code with other database)
  1. Dim myReader As SqlDataReader
  2. conn = GetConnect()
  3. conn.Open()
  4. Dim temp As String
  5. Try
  6. Dim sql As String = "Select Count (*) AS 'KODE' from FILENAME where fieldname = '" & Trim(textbox.text) & "'"
  7. Dim comm As SqlCommand = New SqlCommand(sql, conn)
  8. myReader = comm.ExecuteReader
  9. If myReader.HasRows Then
  10. While myReader.Read()
  11. temp = myReader.Item("KODE")
  12. End While
  13. End If
  14. myReader.Close()
  15. Catch ex As Exception
  16. End Try
  17. conn.Close()
  18.  
  19. If temp = 0 then
  20. 'Do Something
  21. End If
Last edited by Jx_Man : Jul 19th, 2008 at 1:01 pm.
Never tried = Never Know
So, Please do something before post your thread.
* PM Asking will be ignored *
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb VB.NET Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Other Threads in the VB.NET Forum

All times are GMT -4. The time now is 5:35 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC