Wrox Programmer Forums
|
Classic ASP Databases Discuss using ASP 3 to work with data in databases, including ASP Database Setup issues from the old P2P forum on this specific subtopic. See also the book forum Beginning ASP.NET Databases for questions specific to that book. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 17th, 2005, 01:54 AM
Authorized User
 
Join Date: May 2005
Posts: 92
Thanks: 0
Thanked 0 Times in 0 Posts
Default Displaying 2 datatables in 1 datagrid

Dear All,
i am trying to display 2 datatables in a single datagrid with the following code:

private void Page_Load(object sender, System.EventArgs e)
{
// Filling DataSets
      SqlConnection myconn=new SqlConnection(connstr);
      SqlDataAdapter da1=new SqlDataAdapter("select * from emp_Pers", myconn);
      SqlDataAdapter da2=new SqlDataAdapter("select * from emp_Off", myconn);

    DataSet ds1=new DataSet();
    DataSet ds2=new DataSet();

    da1.Fill(ds1, "emp_Pers");
    da2.Fill(ds1, "emp_Pers");

// Setting Primary Keys
        DataColumn pk1;
    DataColumn pk2;

    pk1(0)=ds1.Tables[0].Columns["EmployeeID"];
    ds1.Tables[0].PrimaryKey =pk1;


    pk2(0)=ds2.Tables[0].Columns["EmployeeID"];
    ds2.Tables[0].PrimaryKey =pk2;

// Merging DataSets
    ds1.Merge(ds2, false, MissingSchemaAction.Add);

// Binding to DataGrid
    dgrid.DataSource =ds1;
    dgrid.DataBind();

}

The places where i am getting error is highlighted in RED.
And d errors are:

1)'pk1' denotes a 'variable' where a 'method' was expected

2)Cannot implicitly convert type 'System.Data.DataColumn' to 'System.Data.DataColumn[]'

3)'pk2' denotes a 'variable' where a 'method' was expected

4)Cannot implicitly convert type 'System.Data.DataColumn' to 'System.Data.DataColumn[]'

please help me out.

Thanks & Regards,
Muskaan. :)





 
Old May 17th, 2005, 07:35 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Right, use [] instead of () for arrays; but the problem is you need a DataColumn[] array declared and not a DataColumn type for that to work first and foremost.

DataColumn[] pk1 = new DataColumn[] {ds1.Tables[0].Columns["EmployeeID"]};
ds1.Tables[0].PrimaryKey = pk1;

Brian
 
Old May 17th, 2005, 07:58 AM
Authorized User
 
Join Date: May 2005
Posts: 92
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Brian, but now am getting runtime error as :

"System.ArgumentException: These columns don't currently have unique values"
at the following line:
ds1.Tables[0].PrimaryKey = pk1 ;


plz help out.

Regards,
Muskaan..

 
Old May 18th, 2005, 04:38 AM
Authorized User
 
Join Date: May 2005
Posts: 92
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Can anybody help me out with my problem.

 
Old May 19th, 2005, 07:46 AM
Authorized User
 
Join Date: Jul 2004
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to raj_makro
Default

It seems the data in the column you are assigning as primary key is containing some duplicate values. Remove those duplicate values and try again.

Regards
Raj
 
Old May 19th, 2005, 11:36 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Yes, there is some duplicated data is what it is saying, you can combine columns for the primary key or use another key that is unique.

Brian





Similar Threads
Thread Thread Starter Forum Replies Last Post
Displaying Columns in a DataGrid jmss66 VB How-To 0 July 26th, 2007 03:13 PM
Displaying Images in a DataGrid RichardOrmiston ASP.NET 1.0 and 1.1 Basics 1 December 13th, 2005 01:13 PM
2 x DataTables and Datagrid Vince ADO.NET 0 September 22nd, 2003 08:57 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.