VB.Net中Integer的String.Format不正确

时间:2015-10-08 20:58:53

标签: vb.net visual-studio-2012 string-formatting

这不应该发生,所以我必须遗漏一些简单的东西。

在下面的VB函数中,我试图使用以下格式语句生成要在屏幕上显示的部件号列表:

ticket = String.Format("{0:000}-{1:00000}-{2:00}", storeNumber, order, release)

有了这个,票证应该具有格式xxx-yyyyy-zz,以便票证是人类可读的,我的应用程序的其他部分可以解析这些数据。

Public Shared Function GetShipTickets(storeNumber As Integer, auditor As String, startDate As DateTime) As ShipTickets
    Dim list As New ShipTickets(auditor)
    list.Display = String.Format("Since {0:MMMM d}.", startDate)
    Const sqlCmd As String =
        "SELECT TICKET_STORE, TICKET_ORDER, TICKET_RELEASE " &
        "FROM TBLRELHDR " &
        "WHERE TICKET_STORE=@TICKET_STORE AND STATUS='C' AND @CREATE_DATE<=CREATE_DATE " &
        "ORDER BY TICKET_ORDER, TICKET_RELEASE, CREATE_DATE; "
    Dim table As New DataTable()
    Using cmd As New DB2Command(sqlCmd, Db2CusDta)
        cmd.Parameters.Add("TICKET_STORE", DB2Type.SmallInt).Value = storeNumber
        cmd.Parameters.Add("CREATE_DATE", DB2Type.Char, 8).Value = String.Format("{0:yyyyMMdd}", startDate)
        table.Load(cmd.ExecuteReader())
    End Using
    If 0 < table.Rows.Count Then
        For Each row As DataRow In table.Rows
            Dim order As String = String.Format("{0}", row("TICKET_ORDER")).Trim().ToUpper()
            Dim release As String = String.Format("{0}", row("TICKET_RELEASE")).Trim().ToUpper()
            Dim ticket As String = String.Format("{0:000}-{1:00000}-{2:00}", storeNumber, order, release)
            list.Add(ticket)
        Next
    End If
    list.Sort()
    Return list
End Function
但是,它不起作用。

VS_debugger_screenshot

此外,当我在屏幕上查看我的数据时,它也无法正确显示:

screen_screenshot

发生了什么事?

VB不是我最强的编程语言。要么我不知道VB的一些细微差别,要么编译器搞乱了。

使用Visual Studio 2012

0 个答案:

没有答案