我正在編寫一個程序來獲取「患者」的幾個字段並將數據序列化爲XML。我抓住所有的信息如下:如何序列化VB中的列表?
Dim pacients As New List(Of Patients)
Dim p As New Patients
p.mFirstName = txtFirstName.ToString
p.mlastName = txtLastName.ToString
p.mInsurance = txtInsurance.ToString
p.mDOB = txtDateOfBirth.ToString
p.mEmail = txtEmail.ToString
p.mPhone = txtPhone.ToString
p.mPlanID = txtPhone.ToString
p.mSubID = txtSubID.ToString
這是大錯誤的部分(這是由不同的「全部保存」按鈕,在這裏作爲代碼之前的「添加到部分觸發列表'按鈕):
Dim writer As New StreamWriter(PatientFileName.PatientFileName)
Dim serial As New XmlSerializer(GetType(Patients))
serial.Serialize(writer, pacients) 'in this line it just says there was an error generating the xml document
writer.Close()
如果患者類是必需的,我會發布它。
您已經添加了'Serializable'屬性,你的'Patients'類?另外,發佈完整的錯誤通常是一個好主意。 – DeanOC 2014-09-19 00:41:56
我認爲你需要使用文件流,而不是streamwriter – Plutonix 2014-09-19 00:43:22
@DeanOC這實際上就是它所說的「生成XML文檔時出錯」和「InvalidOperationException未處理」 – user1404664 2014-09-19 00:54:59