私は現在、データベースから多くのデータをインポートし、xsdスキーマに一致するxmlとして出力する必要がある場合に取り組んでいます。私はxsd.exeを使用して、特定のスキーマのC#クラスを生成しました。データベースからxsd.exeから作成されたcassを埋める方法
私の質問は、このクラスを使用してデータベースからデータを取り込む方法です。私はこの中に移入する「ttc_queue」の複数の要素を持つことになります `
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.0.30319.33440")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true, Namespace = "TTC_Queue")]
[System.Xml.Serialization.XmlRootAttribute(Namespace = "MT_Queue", IsNullable = false)]
public partial class STAGING_Low
{
private object[] itemsField;
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute("TTC_Queue", typeof(TTC_Queue))]
[System.Xml.Serialization.XmlElementAttribute("ROW_COUNTS", typeof(ROW_COUNTS))]
public object[] Items
{
get
{
return this.itemsField;
}
set
{
this.itemsField = value;
}
}
}
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.0.30319.33440")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true, Namespace = "TTC_Queue")]
public partial class TTC_Queue
{
private System.Data.SqlTypes.SqlDecimal reportingUnitCodeField;
private bool reportingUnitCodeFieldSpecified;
private System.Data.SqlTypes.SqlString preparerNField;
//more fields
`
:
私のクラスは次のようになります。 これで使用されるttc_queueのオブジェクト[]がすでに設定されています。
この配列を「アイテムフィールド」に設定してこれを逆シリアル化するにはどうすればよいですか?
は、私は現在持っている:
An unhandled exception of type 'System.InvalidCastException' occurred in mscorlib.dll
Additional information: Object cannot be stored in an array of this type.
私が欠けているかわからないんだけど:
STAGING_low low = new STAGING_Low();
low.Items = new TTC_Queue[1];
low.Items.SetValue(myObject[],0);
私は値を設定しています私はエラーを取得します。
ご協力いただきありがとうございます。
これは私が必要とするようにデータを作成して作成しました。ただし、各レコードについては、
データセットは複数のテーブルで構成されているため、DataTable dt = new DataTable()を使用できます。アダプター。充填(dt); ds.Tables.Add(dt);各テーブルにはnameプロパティがあり、次のようにテーブル名を変更できます。dt.TableName = "New Table Name";またはコンストラクタnew DataTable( "テーブル名")。 DataTableでカラム名を変更するには、次のようにデータベースのクエリの 'AS'を使用します。SELECT COLA as abc – jdweng
これは完全に機能しました。ありがとうございました。 – orlando15767