Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7998859
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T15:20:07+00:00 2026-06-04T15:20:07+00:00

I am selecting a distinct user from IT_Cases_List and stored it in an arraystaff()

  • 0

I am selecting a distinct user from IT_Cases_List and stored it in an arraystaff().
From this array, I will then call a Stored Procedure to count the no of cases attended by this user,(arraystaff(i)) and loop it until arraystaff.length-1

but the problem is that the count does not tally.

Sub getStaff(ByVal month As String)
    If Not con.State = ConnectionState.Closed Then
        con.Open()
    End If
    Dim s As String = "select distinct Attended_by from IT_Cases_List where month(Resolution_date) ='" & month & "' "
    s = s & "And Year(Resolution_date) ='" & ddyear.SelectedValue & "' and Attended_by is not null "
    cmd = New SqlCommand(s, con)
    da = New SqlDataAdapter
    ds = New DataSet
    da.SelectCommand = cmd
    da.Fill(ds)
    If ds.Tables(0).Rows.Count > 0 Then
        staffcount = ds.Tables(0).Rows.Count
        ReDim arrstaff(staffcount - 1)
        For Me.i = 0 To staffcount - 1
            arrstaff(i) = ds.Tables(0).Rows(i).Item("Attended_by")
        Next
            getCases()
     End If
End Sub

Sub getCases()
    If con.State = ConnectionState.Closed Then
        con.Open()
    End If

    ReDim arrdata(arrstaff.Length - 1, 0)
    For Me.i = 0 To arrstaff.Length - 1
        cmd = New SqlCommand("get_cases", con)
        cmd.CommandType = CommandType.StoredProcedure
        cmd.Parameters.Add("@ename", SqlDbType.VarChar).Value = arrstaff(i)
        cmd.Parameters.Add("@Yr", SqlDbType.VarChar).Value = ddyear.SelectedValue
        cmd.Parameters.Add("month", SqlDbType.VarChar).Value = m

        cmd.ExecuteNonQuery()
        da = New SqlDataAdapter()
        da.SelectCommand = cmd
        ds = New DataSet
        da.Fill(ds)

        If Not IsDBNull(ds.Tables(0).Rows(i).Item("NoCase")) Then
            arrdata(i, 0) = ds.Tables(0).Rows(i).Item("NoCase")
        End If
    Next

    cmd = New SqlCommand("delete from cases_Temp", con)
    cmd.ExecuteNonQuery()
    con.Close()
End Sub

and this is my stored procedure

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

ALTER procedure [dbo].[get_cases](
@Ename  varchar(100),
@Yr varchar(50),
@month varchar(30))

 AS
BEGIN
declare @NoCase as int

select @NoCase=COUNT(*)
from IT_Cases_List
where Attended_by= @Ename and month(Resolution_date) =@month and 
Year(Resolution_date)=@Yr and Attended_by is not null 


insert into cases_temp(Ename,NoCase)
values(@Ename,@NoCase)

select * from cases_Temp

end

i don’t know what have i done wrong.
any help will be much appreciated.

UPDATE

ok, i’ve called only once getcases but i’m still having the same problem.

this is what i get when i run the program:

http://imgur.com/dkhmU

if i get Count(*) from the database, the total no of cases i should be getting is 132, whereas the total of cases i get from the program is 157 (7+7+20+20+49+49+5)

if i run the query from sql, this is what i should be getting
enter image description here

i notice that the Count number gets duplicated (7,7,20,20,49,49,5) instead of (7,20,49,5,10,27,13)

can anybody tell me what have i done wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T15:20:08+00:00Added an answer on June 4, 2026 at 3:20 pm

    You should have called getCases() only once because inside it has a loop for each staff (arraystaff). Another thing, can you provide us a little more info regarding the problem? eg. sample records, desired output so we can more help you 🙂

    UPDATE 1

    move the ds = New DataSet before the For Loop, and pass the Command Object to the DataAdapter Object.

    Sub getCases()
        If con.State = ConnectionState.Closed Then
            con.Open()
        End If
    
        ReDim arrdata(arrstaff.Length - 1, 0)
    
        ds = New DataSet
        For Me.i = 0 To arrstaff.Length - 1
    
            cmd = New SqlCommand("get_cases", con)
            cmd.CommandType = CommandType.StoredProcedure
            cmd.Parameters.Add("@ename", SqlDbType.VarChar).Value = arrstaff(i)
            cmd.Parameters.Add("@Yr", SqlDbType.VarChar).Value = ddyear.SelectedValue
            cmd.Parameters.Add("month", SqlDbType.VarChar).Value = m
    
            da = New SqlDataAdapter(cmd)
            da.Fill(ds)
    
            If Not IsDBNull(ds.Tables(0).Rows(i).Item("NoCase")) Then
                arrdata(i, 0) = ds.Tables(0).Rows(i).Item("NoCase")
            End If
    
        Next
    
        cmd = New SqlCommand("delete from cases_Temp", con)
        cmd.ExecuteNonQuery()
        con.Close()
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How efficient is this query. It's selecting from the same table twice from within
I'm selecting my data with the following statement: select distinct min(revision_number) as revno,po_number from
I'm selecting my data with the following statement: select distinct min(revision_number) as revno,po_number from
I am selecting everything from prod_drop and joining 2 other tables for additional data.
Possible Duplicate: Selecting data from two different servers in SQL Server How can I
I'm having problem selecting an element with an id like this <li =0f:Bactidol_Recorder.mp4>. I
Has anybody bench marked selecting elements with id's and class's from CSS and javascript?
In mysql i m selecting from a table shouts having a foreign key to
I'm trying to do the following in MySQL: SELECT DISTINCT field FROM table WHERE
i have a query that goes like this: $get_feed_amount = mysql_query( SELECT COUNT(*) as

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.