index and length must refer to a loction with in the string
Parameter name : length
มันเกิดจากสาเหตุอะไรครับ รบกวนช่วยชี้แนะด้วยครับ
Code (VB.NET)
Sub autoid()
Dim sqlBill As String = ""
Dim Year As Integer = Date.Now.Year
Try
sqlBill = "select cost_id FROM Cost order by cost_id"
connect()
With da
.SelectCommand = New OleDbCommand(sqlBill, conn)
.Fill(ds, "cost_id")
End With
Dim count As Integer = ds.Tables("cost_id").Rows.Count
If (count > 0) Then
Dim ID As String = ds.Tables("cost_id").Rows(count - 1).Item("cost_id")
Dim num As String = Convert.ToInt32(id.Substring(5, 10))
num += 1
txtcost_id.Text = num.ToString("C" & Year.ToString & "00000")
ElseIf (count = 0) Then
txtcost_id.Text = "C" & Year.ToString & "00001"
End If
Catch ex As Exception
MessageBox.Show("เกิดข้อผิดพลาด เนื่องจาก " & ex.Message, "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Information) 'โชว์ messagebox เเจ้งผู้ใช้
conn.Close()
End Try
End Sub
Tag : .NET, Ms SQL Server 2005, Win (Windows App), VS 2005 (.NET 2.x)