将最后一个id从sql递增到vb10

时间:2013-03-30 13:55:40

标签: sql-server vb.net visual-studio-2010

我想增加一个号码。从sql它应该像这13-001但它使13-1这里是我的代码

Private Sub getLastID()

    Dim dr As SqlDataReader
    Dim Cmd As New SqlCommand
    con.Open()
    With Cmd
        .Connection = con
        .CommandText = "SELECT * FROM tbl_student ORDER BY Student_no DESC"
    End With
    dr = Cmd.ExecuteReader

    If dr.Read Then
        lblStudentNo.Text = Val(dr.Item(0)) + 1
    End If

    con.Close()
End Sub

我该怎么办?谢谢

1 个答案:

答案 0 :(得分:1)

您可以使用PadLeft方法。

试试这个:

 lblStudentNo.Text = Val(dr.Item(0)) & "-" & "1".PadLeft(3, "0")