none
Possible Bug with SqlDataAdapter.Fillschema DataColumn.Unique values are not populated. RRS feed

  • Question

  • Hi all,

    I have done a lot of searching for answer to this problem this evening and so far have not found a solution but have found multiple people with the same issue.

    When using SqlDataAdapter.FillSchema() from a table that contains a Primary Key and columns with Unique constraints the only DataColumn.Unique value to be populated is the Primary Key.

    From reading the MSDN entry for dbDataAdapter this is not the intended functionality

    Can anyone suggest avenues to try or where to raise this issue if the method truly is not functioning as intended?

    • Moved by Fred BaoModerator Wednesday, March 11, 2015 5:22 AM Ado.NET DataSet Related
    Tuesday, March 10, 2015 12:41 AM

Answers

  • Hello HarborneD,

    >>When using SqlDataAdapter.FillSchema() from a table that contains a Primary Key and columns with Unique constraints the only DataColumn.Unique value to be populated is the Primary Key.

    From your description, it is not very clear how your table is defined, I tried to reproduce this issue with below table(not sure if it is similar with yours, if not, please share it with us):

    CREATE TABLE [dbo].[T20141230] (
    
        [ID]       INT        NOT NULL,
    
        [Name]     NCHAR (10) NULL,
    
        [Birthday] DATETIME   NULL,
    
        PRIMARY KEY CLUSTERED ([ID] ASC),
    
           CONSTRAINT uc_PersonID UNIQUE ([Name])
    
    );
    

    And the code used to full the schema:

    SqlConnection con = new SqlConnection(@"Server=(localdb)\Projects;Database=ADO.NET;Trusted_Connection=True;");
    
                    try
    
                    {
    
                        con.Open();
    
                        SqlCommand cmd = new SqlCommand("select * from [T20141230]", con);
    
                        SqlDataAdapter da = new SqlDataAdapter(cmd);
    
                        DataTable dt = new DataTable();
    
                        da.FillSchema(dt, SchemaType.Mapped);
    
                        da.Fill(dt);
    
                    }
    
                    catch (Exception)
    
                    {
    
                    }
    
                    finally
    
                    {
    
                        con.Close();
    
                    }
    

    However, I could all columns populated with values from database. I used VS2013, .NET 4.5 and windows 8.1, you could have a try with my demo.

    >>Can anyone suggest avenues to try or where to raise this issue if the method truly is not functioning as intended

    If it is an exact issue which is not reported yet, you could post it to this site below:

    https://connect.microsoft.com/VisualStudio

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, March 11, 2015 5:43 AM
    Moderator

All replies

  • Hello HarborneD,

    >>When using SqlDataAdapter.FillSchema() from a table that contains a Primary Key and columns with Unique constraints the only DataColumn.Unique value to be populated is the Primary Key.

    From your description, it is not very clear how your table is defined, I tried to reproduce this issue with below table(not sure if it is similar with yours, if not, please share it with us):

    CREATE TABLE [dbo].[T20141230] (
    
        [ID]       INT        NOT NULL,
    
        [Name]     NCHAR (10) NULL,
    
        [Birthday] DATETIME   NULL,
    
        PRIMARY KEY CLUSTERED ([ID] ASC),
    
           CONSTRAINT uc_PersonID UNIQUE ([Name])
    
    );
    

    And the code used to full the schema:

    SqlConnection con = new SqlConnection(@"Server=(localdb)\Projects;Database=ADO.NET;Trusted_Connection=True;");
    
                    try
    
                    {
    
                        con.Open();
    
                        SqlCommand cmd = new SqlCommand("select * from [T20141230]", con);
    
                        SqlDataAdapter da = new SqlDataAdapter(cmd);
    
                        DataTable dt = new DataTable();
    
                        da.FillSchema(dt, SchemaType.Mapped);
    
                        da.Fill(dt);
    
                    }
    
                    catch (Exception)
    
                    {
    
                    }
    
                    finally
    
                    {
    
                        con.Close();
    
                    }
    

    However, I could all columns populated with values from database. I used VS2013, .NET 4.5 and windows 8.1, you could have a try with my demo.

    >>Can anyone suggest avenues to try or where to raise this issue if the method truly is not functioning as intended

    If it is an exact issue which is not reported yet, you could post it to this site below:

    https://connect.microsoft.com/VisualStudio

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, March 11, 2015 5:43 AM
    Moderator
  • You are sure you use that, because I miss attributes.

     SqlDataAdapter.FillSchema()

    https://msdn.microsoft.com/en-us/library/229sz0y5%28v=vs.110%29.aspx?f=255&MSPPError=-2147217396


    Success
    Cor

    Wednesday, March 11, 2015 12:26 PM