Vb.net 使用Web服务将Infopath重复表数据提交到SQL
这是我第一次使用XML序列化,我不确定是否可以提交嵌套的重复表,或者如何在数组中序列化数组 我有一个Infopath表单,在“资源”重复表中有一个“周”重复表。这是XML输出:Vb.net 使用Web服务将Infopath重复表数据提交到SQL,vb.net,web-services,xml-serialization,infopath,Vb.net,Web Services,Xml Serialization,Infopath,这是我第一次使用XML序列化,我不确定是否可以提交嵌套的重复表,或者如何在数组中序列化数组 我有一个Infopath表单,在“资源”重复表中有一个“周”重复表。这是XML输出: <my:AllocateResource> <my:Resource> <my:Person> <my:DisplayName>User 1</my:DisplayName> <my:
<my:AllocateResource>
<my:Resource>
<my:Person>
<my:DisplayName>User 1</my:DisplayName>
<my:AccountId>49808</my:AccountId>
<my:AccountType>User</my:AccountType>
</my:Person>
</my:Resource>
<my:Weeks>
<my:WeekNumber>24</my:WeekNumber>
<my:Hours>20</my:Hours>
</my:Weeks>
<my:Weeks>
<my:WeekNumber>28</my:WeekNumber>
<my:Hours>15</my:Hours>
</my:Weeks>
<my:RequestID>1</my:RequestID>
<my:StartDate>2013-08-01</my:StartDate>
<my:EndDate>2013-08-14</my:EndDate>
</my:AllocateResource>
<my:AllocateResource>
<my:Resource>
<my:Person>
<my:DisplayName>User2</my:DisplayName>
<my:AccountId>49841</my:AccountId>
<my:AccountType>User</my:AccountType>
</my:Person>
</my:Resource>
<my:Weeks>
<my:WeekNumber>25</my:WeekNumber>
<my:Hours>10</my:Hours>
</my:Weeks>
<my:RequestID>2</my:RequestID>
<my:StartDate>2013-08-01</my:StartDate>
<my:EndDate>2013-08-14</my:EndDate>
</my:AllocateResource>
好的,我想出了一个简单的方法来解决这个问题: Visual Studio 2012有一个XSD模式到序列化编码工具 在Infopath中,将表单另存为源(从“文件”菜单) 然后转到启动-->Visual Studio-->Visual Studio工具-->开发人员命令提示符。导航到保存infpath源的目录,然后键入:
xsd myschema.xsd /classes
我还补充说
/language:VB
之后得到VB代码。它将以正确的格式将代码保存到同一文件夹中。这比自己写要容易得多。与论坛网站不同,我们不使用“谢谢”或“感谢任何帮助”或签名。见“和”。
Public Sub SubmitRepeatingTable(myRepTable As RepeatingTable)
Dim myConnection As SqlConnection = New SqlConnection()
myConnection = New SqlConnection(connectionString)
myConnection.Open()
Dim Command As New SqlClient.SqlCommand("usp_add_allocation")
Command.CommandType = CommandType.StoredProcedure
Command.Connection = myConnection
For i As Integer = 0 To myRepTable.Resource.Length - 1
Dim RequestID As Integer = myRepTable.RequestID
Dim AccountID As String = myRepTable.Resource(i).Person(i).AccountId
Dim StartDate As String = myRepTable.StartDate
Dim EndDate As String = myRepTable.EndDate
For j As Integer = 0 To myRepTable.Resource(i).Weeks.Length - 1
Dim WeekNumber As Integer = myRepTable.Resource(i).Weeks(j).WeekNumber
Dim Hours As Decimal = myRepTable.Resource(i).Weeks(j).Hours
xsd myschema.xsd /classes
/language:VB