현재 데이터베이스에서 많은 데이터를 가져 와서 xsd 스키마와 일치하는 xml로 출력해야하는 경우를 처리하고 있습니다. xsd.exe를 사용하여 특정 스키마에 대한 C# 클래스를 생성했습니다.C# 데이터베이스에서 xsd.exe에서 만든 채우기 방법
내 질문은 어떻게이 클래스를 사용하여 데이터베이스에서 데이터를 채울 수 있습니까?
내 클래스는 다음과 같다 :`
[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"여러 요소가됩니다. 여기에 이미 ttc_queue의 객체 []가 채워져 있습니다.
"항목 필드"로이 배열을 설정 한 다음이 또한 deserialize합니까?
는 내가 현재 가지고 :
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);
내가 값을 설정하고있어 내가 오류가 발생합니다.
도움을 주셔서 감사합니다.
필자는 필자가 필요로하는 것처럼 데이터를 작성하고 XML로 작성했습니다. 그러나 각 레코드는
데이터 집합은 여러 테이블로 구성되어 있으므로 DataTable dt = new DataTable(); adapter.Fill (dt); ds.Tables.Add (dt); 각 테이블에는 name 속성이 있으므로 다음과 같이 테이블 이름을 변경할 수 있습니다. dt.TableName = "New Table Name"; 또는 생성자 new DataTable ("table name"); 다음과 같이 데이터베이스에 대한 쿼리에서 'AS'를 사용하여 DataTable의 열 이름을 변경할 수 있습니다. SELECT COLA as abc – jdweng
이것은 완벽하게 작동했습니다. 고맙습니다. – orlando15767