Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Datagrid returns table values twice

Posted on 2005-03-03
6
Medium Priority
?
175 Views
Last Modified: 2010-04-16
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();


                  }
            }
0
Comment
Question by:devlins
  • 3
  • 2
6 Comments
 
LVL 8

Expert Comment

by:gena17
ID: 13450279
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
 

Author Comment

by:devlins
ID: 13451098
DS is the dataset.Tables.Add();
ICon was a goof up!
I changed it to LCon which is the database connection
0
 

Author Comment

by:devlins
ID: 13451133
When I want to refresh the page by eventhandler and during pageload that is when I call
LSales_Query
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 8

Assisted Solution

by:gena17
gena17 earned 750 total points
ID: 13451240
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
 

Author Comment

by:devlins
ID: 13452426
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
 
LVL 13

Accepted Solution

by:
dungla earned 750 total points
ID: 13455473
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

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question