G
Guest
My apps are written without using strongly typed dataSets. I am in the process of converting them over but don't want to
rewrite the whole app with STDS at this time. So I am trying to put them into new code and eventually I will get them throughout the app, or at least that is my theory
So I thought I would start by trying to use a STDS from the exsisting dataSets whereever I can but am running into an issue with the primary key. When I create a new Table from the STDS using a table from the dataSet it doesn't copy in the primary key info. See Example below.
So why doesnt the strongly typed DataTable take the primary keys from the table passed to it in its constructor???
public static bool CreateClass(string fullClassName, DataSet dataSet)
{
result = String.Empty;
//Try to Load STDS table from Existing Untyped Table in UnTyped DataSet
RadData.ClassesDataTable classesTable
= new RadData.ClassesDataTable( dataSet.Tables["Classes"] );
//If you check classes table at this point no Primary keys columns were created???
//even though the table passed to it has primary keys (SEE the STDS autoCreated Code Below)
//Also Create a Regular untyped Table
DataTable classesUnTypedTable
= dataSet.Tables["Classes"] ;
//If you checkclassesUnTypedTable at this point it has Primary keys columns as expected
//
int classNameStart = fullClassName.LastIndexOf(".") + 1;
if (classNameStart >= fullClassName.Length - 1
||classNameStart <= 0 )
{
result = "Class Name invalid";
return false;
}
string className = fullClassName.Substring(classNameStart);
string nameSpace = fullClassName.Substring(0,classNameStart - 1);
Object[] keys = new Object[]{className,nameSpace};
//Finds the rows
DataRow rowUntyped
= classesUnTypedTable.Rows.Find(keys);
//Bombs as table has no primary key
RadData.ClassesRow row
= classesTable.FindByClassNameNameSpace(className,nameSpace);
*********************************************************
Here is the AutoMagically generatred code for the STDS from VS 2003
*********************************************************
internal ClassesDataTable(DataTable table) :
base(table.TableName) {
if ((table.CaseSensitive != table.DataSet.CaseSensitive)) {
this.CaseSensitive = table.CaseSensitive;
}
if ((table.Locale.ToString() != table.DataSet.Locale.ToString())) {
this.Locale = table.Locale;
}
if ((table.Namespace != table.DataSet.Namespace)) {
this.Namespace = table.Namespace;
}
this.Prefix = table.Prefix;
this.MinimumCapacity = table.MinimumCapacity;
this.DisplayExpression = table.DisplayExpression;
}
rewrite the whole app with STDS at this time. So I am trying to put them into new code and eventually I will get them throughout the app, or at least that is my theory
So I thought I would start by trying to use a STDS from the exsisting dataSets whereever I can but am running into an issue with the primary key. When I create a new Table from the STDS using a table from the dataSet it doesn't copy in the primary key info. See Example below.
So why doesnt the strongly typed DataTable take the primary keys from the table passed to it in its constructor???
public static bool CreateClass(string fullClassName, DataSet dataSet)
{
result = String.Empty;
//Try to Load STDS table from Existing Untyped Table in UnTyped DataSet
RadData.ClassesDataTable classesTable
= new RadData.ClassesDataTable( dataSet.Tables["Classes"] );
//If you check classes table at this point no Primary keys columns were created???
//even though the table passed to it has primary keys (SEE the STDS autoCreated Code Below)
//Also Create a Regular untyped Table
DataTable classesUnTypedTable
= dataSet.Tables["Classes"] ;
//If you checkclassesUnTypedTable at this point it has Primary keys columns as expected
//
int classNameStart = fullClassName.LastIndexOf(".") + 1;
if (classNameStart >= fullClassName.Length - 1
||classNameStart <= 0 )
{
result = "Class Name invalid";
return false;
}
string className = fullClassName.Substring(classNameStart);
string nameSpace = fullClassName.Substring(0,classNameStart - 1);
Object[] keys = new Object[]{className,nameSpace};
//Finds the rows
DataRow rowUntyped
= classesUnTypedTable.Rows.Find(keys);
//Bombs as table has no primary key
RadData.ClassesRow row
= classesTable.FindByClassNameNameSpace(className,nameSpace);
*********************************************************
Here is the AutoMagically generatred code for the STDS from VS 2003
*********************************************************
internal ClassesDataTable(DataTable table) :
base(table.TableName) {
if ((table.CaseSensitive != table.DataSet.CaseSensitive)) {
this.CaseSensitive = table.CaseSensitive;
}
if ((table.Locale.ToString() != table.DataSet.Locale.ToString())) {
this.Locale = table.Locale;
}
if ((table.Namespace != table.DataSet.Namespace)) {
this.Namespace = table.Namespace;
}
this.Prefix = table.Prefix;
this.MinimumCapacity = table.MinimumCapacity;
this.DisplayExpression = table.DisplayExpression;
}