10-09-17, 02:23 AM
كود :
Sub CL()
Dim GetCode As String = "0"
CMD = New SqlCommand()
CMD.Connection = con
CMD.CommandText = "SELECT TOP(1) * FROM أسم الجدول ORDER BY أسم العمود DESC"
Try
con.Open()
Dim reader As SqlDataReader = CMD.ExecuteReader(CommandBehavior.SingleRow)
If (reader.HasRows = True) Then
While reader.Read()
GetCode = (reader.GetString(reader.GetOrdinal("أسم العمود")))
End While
End If
reader.Close()
Catch ex As System.Exception
MsgBox(ex.Message)
Finally
con.Close()
End Try
If (GetCode = "0") Then
' إذا حاب تظيف لرقم تصنيف
txt_Num_Recorde.Text = "C00001"
ElseIf (GetCode <> "0") Then
Dim TotalCodeWithoutLable As String = GetCode.Count - 1
Dim OldNum As String = GetCode.Substring(GetCode.Length - TotalCodeWithoutLable)
txt_Num_Recorde.Text = "C" + Format(OldNum + 1, "00000").ToString
End If
End Sub