Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#4.0 dataset
I am trying to Merge two DataSets in c# .net framework 4.0, It raised " Mismatch columns in the PrimaryKey : versus " My 1st Dataset is from SQl Server of DataType "Varchar", while Other is from Oracle Database of DataType "Varchar2".
 
OrgStockMaster.PrimaryKey = new DataColumn[] { OrgStockMaster.Columns["PkID001"] }; //SQL Database
 
dtOracleStock.PrimaryKey = new DataColumn[] { dtOracleStock.Columns["PkID001"] }; //Oracle Database
 
While Doing this,
 
dsStockMaster.Merge(StkFrmOracle); DataSet dsDiff = dsStockMaster.GetChanges();
 
It raises this DataException : Mismatch columns in the PrimaryKey : .PkID001 versus .PKID001.
Posted 4-Dec-12 20:39pm
Comments
Krunal Rohit at 5-Dec-12 3:25am
   
use same datatype for PK in both DB...
Singh.pankaj at 5-Dec-12 4:22am
   
string QryForSupp = " Select col1 as PkID001 from ABC ";
 
SqlDataAdapter SqlDAforSupp = new SqlDataAdapter(QryForSupp, Con);
DataSet dsStockMaster = new DataSet();
SqlDAforSupp.Fill(dsStockMaster);
DataTable OrgStockMaster = dsStockMaster.Tables[0];
 
OrgStockMaster.PrimaryKey = new DataColumn[] { OrgStockMaster.Columns["PkID001"] };

 
if (oraConn.State != System.Data.ConnectionState.Open)
{
oraConn.Open();
}
 
string checkQry = "SELECT col1 as PkID001 FROM AAA ";
 
DataSet StkFrmOracle = new DataSet();
OleDbCommand cmdStockMast = new OleDbCommand();
cmdStockMast.CommandText = checkQry;
cmdStockMast.CommandType = CommandType.Text;
cmdStockMast.Connection = oraConn;
OleDbDataAdapter odaForStock = new OleDbDataAdapter(cmdStockMast);
odaForStock.Fill(StkFrmOracle);
 
DataTable dtOracleStock = StkFrmOracle.Tables[0];
 
dtOracleStock.PrimaryKey = new DataColumn[] { dtOracleStock.Columns["PkID001"] };
 
dsStockMaster.Merge(StkFrmOracle); //This line is throwing Exception.
DataSet dsDiff = dsStockMaster.GetChanges();
My Oracle Column is of Data Type "varchar2", while SQL Column is "Varchar".
I think this is why I'm getting exception.
Krunal Rohit at 5-Dec-12 4:25am
   
Ya thats why I've told you to change Table Definition..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Mobile
Web01 | 2.8.140926.1 | Last Updated 5 Dec 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100