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
 Try
            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
            MsgBox(ex.Message)
        End Try
javagairAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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.
0
David L. HansenCEOCommented:
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.
0
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.

gry
0
The 7 Worst Nightmares of a Sysadmin

Fear not! To defend your business’ IT systems we’re going to shine a light on the seven most sinister terrors that haunt sysadmins. That way you can be sure there’s nothing in your stack waiting to go bump in the night.

David L. HansenCEOCommented:
If you put the same query into SQL Server directly (management studio) does the same result occur?
0
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.
0
David L. HansenCEOCommented:
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.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
javagairAuthor Commented:
david
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.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2008

From novice to tech pro — start learning today.