Datagrid returns table values twice

What would cause a datagrid to return the values from a table twice?

protected void LSales_Query(object sender, EventArgs e)
            {

                  if (ConI.State == ConnectionState.Closed)
                  {
                        ConI.Open ();

                  
                  

                        string S = "(Select * from LSales where Agent = '" + D.SelectedItem.Text + "')";
                  
                        DA = new System.Data.SqlClient.SqlDataAdapter(S, ConI);
                        LConn.Open();
                        DataTable Dtable = new DataTable();
                        //DA.Fill(DS, "LSales");
                        DA.Fill(DS, "LSales");
                        DG.DataSource =DS;
                        DG.DataMember="LSales";
                        DS.Tables.Add();
                        
                        DataBind();

                        LConn.Dispose();


                  }
            }
devlinsAsked:
Who is Participating?
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.

gena17Commented:
Hi, devlins.

Can you explain a little more? Some additional info is needed.

What is ConI and what is LConn?
When do you call LSales_Query() method?
Why do you use: DS.Tables.Add();  ?

Thanks,

Gena
0
devlinsAuthor Commented:
DS is the dataset.Tables.Add();
ICon was a goof up!
I changed it to LCon which is the database connection
0
devlinsAuthor Commented:
When I want to refresh the page by eventhandler and during pageload that is when I call
LSales_Query
0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

gena17Commented:
devlins,

As I understand you see all your rows twice.
What is the order? 1,2,3... 1,2,3...   or   1,1,2,2,3,3...
Are you sure your table contains just one instance of each row?
What is your updated code?
0
devlinsAuthor Commented:
123... 123....

all in the same row, has two of the same table side by side...

The code I posted above is the code that I am using.... which only has a single instance of each...
0
dunglaCommented:
It just because currently, your datagird already have data on it. When you bind new datasource, it will add more to your grid (it mean did not re-bind data).

In your DataBind() function, you need to clear the DataSource first before you bind new datasource to it.

// clear data source
DataGrid.DataSource = null;
// bind new DataSource
DataGrid.DataSource = NewDataSource;
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
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
C#

From novice to tech pro — start learning today.

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.