使用AsEnumerable并允许Null值

时间:2012-08-13 16:52:14

标签: sql xml vb.net dataset

我正在将数据集表值加载到.xml表中。如果有结果,我会通过电子邮件发送此表。如何将空列加载到下面的.xml表中?例如,_New_Invoice_Number偶尔会为Null,因为它是可以为空的值。

 Dim void = _
            <html>
                <body>
                    <table border="1">
                        <tr><th>Store #</th><th>Invoice Date</th><th>Invoice #</th><th>Vehicle Tag</th><th>Void Reason</th><th>Invoice Total</th><th>New Invoice #</th><th>Vehicle Tag</th><th>New Invoice Total</th><th>Re-Tendered?</th><th>User Name</th></tr>
                        <%= From vtest In Me.DataDeliveryServiceDataSet.datatable.AsEnumerable _
                            Select <tr><td><%= vtest.Store_Number %></td>
                                       <td><%= Convert.ToDateTime(vtest.Invoice_Date).ToString("M/d/yy") %></td>
                                       <td><%= vtest.Invoice_Number %></td>
                                       <td><%= vtest.Vehicle_Tag %></td>
                                       <td><%= vtes.Void_Reason %></td>
                                       <td><%= vtest.Invoice_Total %></td>
                                       <td><%= vtest._New_Invoice__ %></td>
                                       <td><%= vtest._Vehicle_Tag %></td>
                                       <td><%= vtest.New_Invoice_Total %></td>
                                       <td><%= vtest._Re_tendered_ %></td>
                                       <td><%= vtest.User_Name %></td></tr> %>
                    </table>
                </body>
            </html>

1 个答案:

答案 0 :(得分:1)

以下是一个例子:

Sub Main()
    Dim a As Nullable(Of Integer)
    Dim b As String

    Dim c = IIf(IsNothing(a), "", a.ToString())
    Dim d = IIf(IsNothing(b), "", b)
End Sub

<td><%= IIf(IsNothing(vtest.Vehicle_Tag), "", vtest.Vehicle_Tag) %></td>
<td><%= IIf(IsNothing(vtest.Invoice_Number), "", vtest.Invoice_Number.ToString()) %></td>

另一种选择是在SQL端处理Null:

select coalesce(Vehicle_Tag, '') from myTable