why is sql query creating duplicates in dataset

for some strange reason this dataset  duplicates all of the values
datestart is april first and datestop is april 15 and I get 1 through 15 and then 1 through 15 as second time.  the selection is a social security number
I have checked the database, there are no duplicates.  I am working in asp.net using vb.
does anyone know why the dataset would create duplicates?

thanks gary
            Dim sqlthisPeriod3 As String = "Select * from EmployeeMonthlyrecord where workdate between '" & CDate(datestart) & "' and '" & CDate(datestop) & "' and EMPLOYEEID = '" & Dst.Tables("Dsthireinfo").Rows(0).Item(0).ToString() & "'  "
            Dim adapter35 As SqlDataAdapter = New SqlDataAdapter(sqlthisPeriod3, Connection)
            adapter35.Fill(Dst, "DstthisPeriod3")
        Catch ex As System.Data.SqlClient.SqlException
        End Try
Who is Participating?
David L. HansenProgrammer AnalystCommented:
Yes, global variables of any type have to be carefully monitored because so much has access to it and can change it without the left hand knowing what the right is doing (I'm sure you are aware of this; however, just in case you're not, one rather important principle of programming is to keep as many variables, as close to where they are being used, as possible (ie. only use global variables when you absolutely must). <honestly, I'm far from perfect in exercising this rule myself> ;)

Glad it worked out and I hope we were helpful.
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
(SQL speaking only)

The biggest reason duplicates happens is a JOIN between two tables/views where the ON clause does not contain all columns where the two tables are related.  OR one of the tables is a one-to-many, there are more than one row for the given value in the first table, and the duplicate is by design.

Is EmployeeMonthlyrecord a table or a view?   Since your query only references one object, if it's a table then obviously this shouldn't be happening, and perhaps there is other ASP.NET code that is causing this.

Can't hurt if you do a Debug.Print sqlthisPeriod3 , execute, then post the results into this question.
David L. HansenProgrammer AnalystCommented:
You may need to clear the grid (or even its datasource) before handing the query results to it.

Also, I'd recommend against using BETWEEN for date ranges. See this.
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

javagairAuthor Commented:
first there is no join.
second I am breaking the program the line after the dataset is created and it has two of everything straight out of the sql datatable.

David L. HansenProgrammer AnalystCommented:
If you put the same query into SQL Server directly (management studio) does the same result occur?
javagairAuthor Commented:
David ,no only single entries appear if I run it in the sql server.

the dataset was declared as a global when the webpage opens.
I tried clearing and destroying every table in a dataset on leaving a function, this did not help.
Then I decided to create a different dataset for each function, this worked and the extra lines disappeared.  I am thinking I should have declared the dataset In each function and then cleared it on leaving.
javagairAuthor Commented:
yes I know but sometimes one thinks I'll just slip on in here just to make things simple.  Lazy usually bites you in the you know where.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.