'For Loop Dim i As Integer = Convert.ToInt32(OrderQuantity.Trim) Dim FinalSN As String = "" For sn As Integer = 1 To i FinalSN = GenSerial() Dim SW1 As StreamWriter Dim FS1 As FileStream FS1 = New FileStream("c:\Temp\" & PO & ".txt", FileMode.Append) SW1 = New StreamWriter(FS1) SW1.WriteLine(Part.Trim & ":" & Description.Trim & ":" & "SN:" & FinalSN.Trim) SW1.Close() SerialArray.Add(FinalSN) con2.Close() Dim strCommand3 As String = "INSERT INTO SerialNo (SerialNumbers) values ('" & FinalSN & "')" Dim cm3 As New SqlClient.SqlCommand(strCommand3, con2) con2.Open() Try cm3.ExecuteNonQuery() Catch ex As Exception MessageBox.Show(ex.Message, "Error") End Try FinalSN = "" Next
'Function for creating codes Public Function GenSerial() As String Dim xCharArray() As Char = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".ToCharArray Dim xNoArray() As Char = "0123456789".ToCharArray Dim xGenerator As System.Random = New System.Random() Dim xStr As String = String.Empty While xStr.Length < 15 If xGenerator.Next(0, 2) = 0 Then xStr &= xCharArray(xGenerator.Next(0, xCharArray.Length)) Else xStr &= xNoArray(xGenerator.Next(0, xNoArray.Length)) End If End While Return xStr End Function
select newid() NewID;
select substring(replace(newid(),'-',''),1,15) NewID_15;
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)