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

x
?
Solved

These columns don't currently have unique values.

Posted on 2006-05-25
14
Medium Priority
?
3,923 Views
Last Modified: 2012-06-27

Hello, i have this code and when I run it is giving the folowing error:

Error while populating WebDatagrid: These columns don't currently have unique values.
private void PopulateUnassignedData(string ChildTitle)
    {
        try
        {
            SqlConnection StrConn = new SqlConnection(ConfigurationManager.AppSettings["StrConnectionString"]);
            daUnassignedData = new SqlDataAdapter("UH_GetUnassignedNode", StrConn);

            daUnassignedData.SelectCommand.CommandType = CommandType.StoredProcedure;
            daUnassignedData.SelectCommand.Parameters.Add(new SqlParameter("@Title", SqlDbType.NVarChar, 30));
            // daUnassignedData.SelectCommand.Parameters["@Title"].Value = Request["ChildTitle"];//"Account Manager";
            daUnassignedData.SelectCommand.Parameters["@Title"].Value = "Account Executive";
            daUnassignedData.MissingSchemaAction = MissingSchemaAction.AddWithKey;
            daUnassignedData.Fill(ds, "TblUnassigned");

            DataColumn[] pk = new DataColumn[1];
            pk[0] = ds.Tables["TblUnassigned"].Columns["EMPLOYEE_ID"];
            ds.Tables["TblUnassigned"].PrimaryKey = pk;

            wgUnassigned.DataSource = ds;
            wgUnassigned.DataBind();

        }
        catch (Exception ex)
        {
            throw new Exception("Error while populating WebDatagrid: " + ex.Message);

        }
    }
it seems that this particular line isn't doing any thing
pk[0] = ds.Tables["TblUnassigned"].Columns["EMPLOYEE_ID"];
            ds.Tables["TblUnassigned"].PrimaryKey = pk;
0
Comment
Question by:jemigossaye
  • 6
  • 4
  • 3
  • +1
14 Comments
 
LVL 35

Expert Comment

by:mrichmon
ID: 16762852
You should check your return results from the stored procedure.  It is possible that you are returning duplicate entries and therefore that is causing this.

Maybe a distinct in the stored procedure would help
0
 

Author Comment

by:jemigossaye
ID: 16762893
I am doing a distinct select in the sproc and it is not retruning a duplicate
0
 
LVL 28

Expert Comment

by:strickdd
ID: 16763067
Try returning the primary key in your result set.
0
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.

 

Author Comment

by:jemigossaye
ID: 16763141
can u tell me how i can do that
0
 
LVL 28

Expert Comment

by:strickdd
ID: 16763199
IN your stored procedures SELECT statement:


SELECT PrimaryKeyColumnName, (rest of the SQL)
0
 

Author Comment

by:jemigossaye
ID: 16763210
well I am doing that an still no change
0
 
LVL 28

Expert Comment

by:strickdd
ID: 16763235
Then try:

Select DISTINCT PrimaryKeyColumnName from TableName UNION (current SELECT in stored proc)
0
 
LVL 35

Expert Comment

by:mrichmon
ID: 16763259
Can you verify that the results have no duplicates.  Have you run the sproc in something like query analyzer and lookd at the results.  Or run the SQL profiler to see what is actually being sent?
0
 

Author Comment

by:jemigossaye
ID: 16763306
yes I run the sproc in query analyzer and there is no duplicate
0
 

Author Comment

by:jemigossaye
ID: 16763322
here is my sproc

CREATE      PROCEDURE [dbo].[UH_GetUnassignedNode]

      @Title nvarchar(30)
AS

SELECT       DISTINCT FULLNAME, TITLE, EMPLOYEE_ID, tblANETRoles.role_pid
FROM               TIUSER
INNER JOIN        tblANETRoles ON TIUSER.TITLE = tblANETRoles.role
WHERE           (EMPLOYEE_ID NOT IN
                          (SELECT     tblANETUserHierarchy.user_pid
                            FROM          tblANETUserHierarchy
                            WHERE      TIUSER.EMPLOYEE_ID = tblANETUserHierarchy.user_pid)) AND (TIUSER.TITLE = @Title)

GO
0
 
LVL 35

Accepted Solution

by:
mrichmon earned 750 total points
ID: 16763913
Okay so is the employee_ID the primary key?

Have you tried:

private void PopulateUnassignedData(string ChildTitle)
    {
        try
        {
            SqlConnection StrConn = new SqlConnection(ConfigurationManager.AppSettings["StrConnectionString"]);
            daUnassignedData = new SqlDataAdapter("UH_GetUnassignedNode", StrConn);

            daUnassignedData.SelectCommand.CommandType = CommandType.StoredProcedure;
            daUnassignedData.SelectCommand.Parameters.Add(new SqlParameter("@Title", SqlDbType.NVarChar, 30));
            // daUnassignedData.SelectCommand.Parameters["@Title"].Value = Request["ChildTitle"];//"Account Manager";
            daUnassignedData.SelectCommand.Parameters["@Title"].Value = "Account Executive";
            daUnassignedData.MissingSchemaAction = MissingSchemaAction.AddWithKey;
            daUnassignedData.Fill(ds, "TblUnassigned");

            ds.Tables[0].PrimaryKey = ds.Tables[0].Columns["EMPLOYEE_ID"];

            wgUnassigned.DataSource = ds;
            wgUnassigned.DataBind();

        }
        catch (Exception ex)
        {
            throw new Exception("Error while populating WebDatagrid: " + ex.Message);

        }
    }
0
 
LVL 25

Expert Comment

by:dstanley9
ID: 16764037
doing a SELECT      DISTINCT doesn't mean that you will get unique EMPLOYEE_ID values; it measn that you will get rows where ALL values are unique.  

In your case, if you have an empolyee with mote than one row in the tblANETRoles table (with different role_pid values), you will get back two rows in the INNER JOIN.

If this is waht you want, that's fine, but you may need to set your primary key to be two columns:  EMPLOYEE_ID and role_pid.

If you truly want a set or unique employee IDs, you need to determine what you want to do if the employee has multiple role IDs

0
 

Author Comment

by:jemigossaye
ID: 16764081
well this seems to solve the problem that is from mirchmon's idea. but dstanley9 u got me thinking i will to look in to that more deeply


DataColumn[] pk = new DataColumn[] {ds.Tables[0].Columns["EmployeeID"]};

thanks guys
0
 
LVL 35

Expert Comment

by:mrichmon
ID: 16765489
WHoops my syntax wasn't exact.  SOrry I was in a rush, glad you figured it out.
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

571 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