hi..... i want to show data i datagridview...

587c270accc1bbf443a3cc1f9d9ddf30

This is my function codes :

Public Function AutoNumber() As String
        Dim cnn As New SqlConnection(StrConn)
        Dim cmmd As New SqlCommand
        Dim dreader As SqlDataReader
        Dim KODE As String
        Dim TAMPUNG As String
        Dim KONTER As String
        Dim SQL As String

        cnn.Open()
        SQL = "SELECT * FROM Seleksi ORDER BY Kd_Seleksi DESC"
        cmmd = New SqlCommand(SQL, cnn)
        dreader = cmmd.ExecuteReader
        If dreader.Read = True Then
            TAMPUNG = Right(dreader.Item("Kd_Seleksi"), 3)
            KONTER = CInt(TAMPUNG) + 1
            KODE = "HS" & Mid("000", 1, 3 - KONTER.Length) & KONTER
        Else
            KODE = "HS001"
        End If
        cnn.Close()
        Return KODE
    End Function

something's wrong... my autonumber in kd_seleksi is not working, i know why, because there is no Kd_Seleksi in table daftar, and the kd_Seleksi is come from autonumber function, so how to make it work...???
would you help me with this????

I can't verify your code, but seems it should work iterating:

Konter = 1 ' intialize
Do While dReader.Read() 
    ' get in Kode a 3char string of Konter filled with zeros at the left, 
    ' prepended by "HS" ("HS001", "HS002", "HS003" and so on):
    Kode = String.Format("HS{0:000}", Konter)
    Konter += 1 ' increment Konter by one
loop

...of course:

 dim Konter as Int32

xrj... thanks for your help.... but i'm sorry i still don't get it... can you explain more detail please...!!

but you're right, they need loop, but maybe with (for) function ...!!

I believe any code is valid, may be (why not?) old fashioned, if achieves the required tasks without errors, all the rest will need improvement. I am almost sure you are aware of Click Here and Click Here

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.