jeg tror ikke man kan kalde det strongly typed dataset det du har der.... det er nærmere et helt almindeligt generisk dataset hvor der er lagt en tabel ind, hvor du skal overholde bestemte typer for at få lov til at lægge noget i den.
med et strongly typed dataset har du f.eks. muligheden for :
new Document().TBLStrings.AddTBLStringsRow(<lige præcis de parametre der skal til for at fylde en række af den type>);
"typestyrken" er gennemgående.... dataset/tabel/række/kolonne.
du opretter et strongly typed dataset i koden på samme måde som generatoren gør det, men det er en lidt halvstor mundfuld... har du set den kode der genereres til dig ?
(du kan lige få et eksempel her på et meget simpelt dataset med én enkelt tabel... jeg tror at du vil finde at det bedst kan betale sig at få vs til at fikse det.... men der findes masser af andre tools til at generere den slags - altså udover det som vs bruger)
//------------------------------------------------------------------------------
// <autogenerated>
// This code was generated by a tool.
// Runtime Version: 1.1.4322.573
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </autogenerated>
//------------------------------------------------------------------------------
namespace EXP2.StronglyTypesDS {
using System;
using System.Data;
using System.Xml;
using System.Runtime.Serialization;
[Serializable()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Diagnostics.DebuggerStepThrough()]
[System.ComponentModel.ToolboxItem(true)]
public class Document : DataSet {
private TBLStringsDataTable tableTBLStrings;
public Document() {
this.InitClass();
System.ComponentModel.CollectionChangeEventHandler schemaChangedHandler = new System.ComponentModel.CollectionChangeEventHandler(this.SchemaChanged);
this.Tables.CollectionChanged += schemaChangedHandler;
this.Relations.CollectionChanged += schemaChangedHandler;
}
protected Document(SerializationInfo info, StreamingContext context) {
string strSchema = ((string)(info.GetValue("XmlSchema", typeof(string))));
if ((strSchema != null)) {
DataSet ds = new DataSet();
ds.ReadXmlSchema(new XmlTextReader(new System.IO.StringReader(strSchema)));
if ((ds.Tables["TBLStrings"] != null)) {
this.Tables.Add(new TBLStringsDataTable(ds.Tables["TBLStrings"]));
}
this.DataSetName = ds.DataSetName;
this.Prefix = ds.Prefix;
this.Namespace = ds.Namespace;
this.Locale = ds.Locale;
this.CaseSensitive = ds.CaseSensitive;
this.EnforceConstraints = ds.EnforceConstraints;
this.Merge(ds, false, System.Data.MissingSchemaAction.Add);
this.InitVars();
}
else {
this.InitClass();
}
this.GetSerializationData(info, context);
System.ComponentModel.CollectionChangeEventHandler schemaChangedHandler = new System.ComponentModel.CollectionChangeEventHandler(this.SchemaChanged);
this.Tables.CollectionChanged += schemaChangedHandler;
this.Relations.CollectionChanged += schemaChangedHandler;
}
[System.ComponentModel.Browsable(false)]
[System.ComponentModel.DesignerSerializationVisibilityAttribute(System.ComponentModel.DesignerSerializationVisibility.Content)]
public TBLStringsDataTable TBLStrings {
get {
return this.tableTBLStrings;
}
}
public override DataSet Clone() {
Document cln = ((Document)(base.Clone()));
cln.InitVars();
return cln;
}
protected override bool ShouldSerializeTables() {
return false;
}
protected override bool ShouldSerializeRelations() {
return false;
}
protected override void ReadXmlSerializable(XmlReader reader) {
this.Reset();
DataSet ds = new DataSet();
ds.ReadXml(reader);
if ((ds.Tables["TBLStrings"] != null)) {
this.Tables.Add(new TBLStringsDataTable(ds.Tables["TBLStrings"]));
}
this.DataSetName = ds.DataSetName;
this.Prefix = ds.Prefix;
this.Namespace = ds.Namespace;
this.Locale = ds.Locale;
this.CaseSensitive = ds.CaseSensitive;
this.EnforceConstraints = ds.EnforceConstraints;
this.Merge(ds, false, System.Data.MissingSchemaAction.Add);
this.InitVars();
}
protected override System.Xml.Schema.XmlSchema GetSchemaSerializable() {
System.IO.MemoryStream stream = new System.IO.MemoryStream();
this.WriteXmlSchema(new XmlTextWriter(stream, null));
stream.Position = 0;
return System.Xml.Schema.XmlSchema.Read(new XmlTextReader(stream), null);
}
internal void InitVars() {
this.tableTBLStrings = ((TBLStringsDataTable)(this.Tables["TBLStrings"]));
if ((this.tableTBLStrings != null)) {
this.tableTBLStrings.InitVars();
}
}
private void InitClass() {
this.DataSetName = "Document";
this.Prefix = "";
this.Namespace = "
http://tempuri.org/SomeDataSet.xsd"; this.Locale = new System.Globalization.CultureInfo("da-DK");
this.CaseSensitive = false;
this.EnforceConstraints = true;
this.tableTBLStrings = new TBLStringsDataTable();
this.Tables.Add(this.tableTBLStrings);
}
private bool ShouldSerializeTBLStrings() {
return false;
}
private void SchemaChanged(object sender, System.ComponentModel.CollectionChangeEventArgs e) {
if ((e.Action == System.ComponentModel.CollectionChangeAction.Remove)) {
this.InitVars();
}
}
public delegate void TBLStringsRowChangeEventHandler(object sender, TBLStringsRowChangeEvent e);
[System.Diagnostics.DebuggerStepThrough()]
public class TBLStringsDataTable : DataTable, System.Collections.IEnumerable {
private DataColumn columnStringsIndex;
private DataColumn columnString1;
private DataColumn columnString2;
private DataColumn columnSomeSmallTime;
internal TBLStringsDataTable() :
base("TBLStrings") {
this.InitClass();
}
internal TBLStringsDataTable(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;
}
[System.ComponentModel.Browsable(false)]
public int Count {
get {
return this.Rows.Count;
}
}
internal DataColumn StringsIndexColumn {
get {
return this.columnStringsIndex;
}
}
internal DataColumn String1Column {
get {
return this.columnString1;
}
}
internal DataColumn String2Column {
get {
return this.columnString2;
}
}
internal DataColumn SomeSmallTimeColumn {
get {
return this.columnSomeSmallTime;
}
}
public TBLStringsRow this[int index] {
get {
return ((TBLStringsRow)(this.Rows[index]));
}
}
public event TBLStringsRowChangeEventHandler TBLStringsRowChanged;
public event TBLStringsRowChangeEventHandler TBLStringsRowChanging;
public event TBLStringsRowChangeEventHandler TBLStringsRowDeleted;
public event TBLStringsRowChangeEventHandler TBLStringsRowDeleting;
public void AddTBLStringsRow(TBLStringsRow row) {
this.Rows.Add(row);
}
public TBLStringsRow AddTBLStringsRow(string String1, string String2, System.DateTime SomeSmallTime) {
TBLStringsRow rowTBLStringsRow = ((TBLStringsRow)(this.NewRow()));
rowTBLStringsRow.ItemArray = new object[] {
null,
String1,
String2,
SomeSmallTime};
this.Rows.Add(rowTBLStringsRow);
return rowTBLStringsRow;
}
public TBLStringsRow FindByStringsIndex(int StringsIndex) {
return ((TBLStringsRow)(this.Rows.Find(new object[] {
StringsIndex})));
}
public System.Collections.IEnumerator GetEnumerator() {
return this.Rows.GetEnumerator();
}
public override DataTable Clone() {
TBLStringsDataTable cln = ((TBLStringsDataTable)(base.Clone()));
cln.InitVars();
return cln;
}
protected override DataTable CreateInstance() {
return new TBLStringsDataTable();
}
internal void InitVars() {
this.columnStringsIndex = this.Columns["StringsIndex"];
this.columnString1 = this.Columns["String1"];
this.columnString2 = this.Columns["String2"];
this.columnSomeSmallTime = this.Columns["SomeSmallTime"];
}
private void InitClass() {
this.columnStringsIndex = new DataColumn("StringsIndex", typeof(int), null, System.Data.MappingType.Element);
this.Columns.Add(this.columnStringsIndex);
this.columnString1 = new DataColumn("String1", typeof(string), null, System.Data.MappingType.Element);
this.Columns.Add(this.columnString1);
this.columnString2 = new DataColumn("String2", typeof(string), null, System.Data.MappingType.Element);
this.Columns.Add(this.columnString2);
this.columnSomeSmallTime = new DataColumn("SomeSmallTime", typeof(System.DateTime), null, System.Data.MappingType.Element);
this.Columns.Add(this.columnSomeSmallTime);
this.Constraints.Add(new UniqueConstraint("DocumentKey1", new DataColumn[] {
this.columnStringsIndex}, true));
this.columnStringsIndex.AutoIncrement = true;
this.columnStringsIndex.AllowDBNull = false;
this.columnStringsIndex.ReadOnly = true;
this.columnStringsIndex.Unique = true;
}
public TBLStringsRow NewTBLStringsRow() {
return ((TBLStringsRow)(this.NewRow()));
}
protected override DataRow NewRowFromBuilder(DataRowBuilder builder) {
return new TBLStringsRow(builder);
}
protected override System.Type GetRowType() {
return typeof(TBLStringsRow);
}
protected override void OnRowChanged(DataRowChangeEventArgs e) {
base.OnRowChanged(e);
if ((this.TBLStringsRowChanged != null)) {
this.TBLStringsRowChanged(this, new TBLStringsRowChangeEvent(((TBLStringsRow)(e.Row)), e.Action));
}
}
protected override void OnRowChanging(DataRowChangeEventArgs e) {
base.OnRowChanging(e);
if ((this.TBLStringsRowChanging != null)) {
this.TBLStringsRowChanging(this, new TBLStringsRowChangeEvent(((TBLStringsRow)(e.Row)), e.Action));
}
}
protected override void OnRowDeleted(DataRowChangeEventArgs e) {
base.OnRowDeleted(e);
if ((this.TBLStringsRowDeleted != null)) {
this.TBLStringsRowDeleted(this, new TBLStringsRowChangeEvent(((TBLStringsRow)(e.Row)), e.Action));
}
}
protected override void OnRowDeleting(DataRowChangeEventArgs e) {
base.OnRowDeleting(e);
if ((this.TBLStringsRowDeleting != null)) {
this.TBLStringsRowDeleting(this, new TBLStringsRowChangeEvent(((TBLStringsRow)(e.Row)), e.Action));
}
}
public void RemoveTBLStringsRow(TBLStringsRow row) {
this.Rows.Remove(row);
}
}
[System.Diagnostics.DebuggerStepThrough()]
public class TBLStringsRow : DataRow {
private TBLStringsDataTable tableTBLStrings;
internal TBLStringsRow(DataRowBuilder rb) :
base(rb) {
this.tableTBLStrings = ((TBLStringsDataTable)(this.Table));
}
public int StringsIndex {
get {
return ((int)(this[this.tableTBLStrings.StringsIndexColumn]));
}
set {
this[this.tableTBLStrings.StringsIndexColumn] = value;
}
}
public string String1 {
get {
try {
return ((string)(this[this.tableTBLStrings.String1Column]));
}
catch (InvalidCastException e) {
throw new StrongTypingException("Cannot get value because it is DBNull.", e);
}
}
set {
this[this.tableTBLStrings.String1Column] = value;
}
}
public string String2 {
get {
try {
return ((string)(this[this.tableTBLStrings.String2Column]));
}
catch (InvalidCastException e) {
throw new StrongTypingException("Cannot get value because it is DBNull.", e);
}
}
set {
this[this.tableTBLStrings.String2Column] = value;
}
}
public System.DateTime SomeSmallTime {
get {
try {
return ((System.DateTime)(this[this.tableTBLStrings.SomeSmallTimeColumn]));
}
catch (InvalidCastException e) {
throw new StrongTypingException("Cannot get value because it is DBNull.", e);
}
}
set {
this[this.tableTBLStrings.SomeSmallTimeColumn] = value;
}
}
public bool IsString1Null() {
return this.IsNull(this.tableTBLStrings.String1Column);
}
public void SetString1Null() {
this[this.tableTBLStrings.String1Column] = System.Convert.DBNull;
}
public bool IsString2Null() {
return this.IsNull(this.tableTBLStrings.String2Column);
}
public void SetString2Null() {
this[this.tableTBLStrings.String2Column] = System.Convert.DBNull;
}
public bool IsSomeSmallTimeNull() {
return this.IsNull(this.tableTBLStrings.SomeSmallTimeColumn);
}
public void SetSomeSmallTimeNull() {
this[this.tableTBLStrings.SomeSmallTimeColumn] = System.Convert.DBNull;
}
}
[System.Diagnostics.DebuggerStepThrough()]
public class TBLStringsRowChangeEvent : EventArgs {
private TBLStringsRow eventRow;
private DataRowAction eventAction;
public TBLStringsRowChangeEvent(TBLStringsRow row, DataRowAction action) {
this.eventRow = row;
this.eventAction = action;
}
public TBLStringsRow Row {
get {
return this.eventRow;
}
}
public DataRowAction Action {
get {
return this.eventAction;
}
}
}
}
}
mvh