?
Solved

Datagrid returns table values twice

Posted on 2005-03-03
6
Medium Priority
?
174 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
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!

 
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

762 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