Private Sub AutoCode()
Cm = New OleDbCommand("Select Max(ProductID)As ProCode From Product", Cn)
Dr.Read()
If Dr("ProCode") Is DBNull.Value Then
TextBox1.Text = "0001"
Else
Procode = Dr("Procode") + 1
Select Case Procode
Case Is < 10
TextBox1.Text = "000" & Procode
Case Is < 100
TextBox1.Text = "00" & Procode
Case Is < 1000
TextBox1.Text = "0" & Procode
Case Is < 10000
TextBox1.Text = Procode
End Select
End If
ติด Error ตรง If Dr("ProCode") Is DBNull.Value Then ครับขอเทพแก้หน่อยครับ
Tag : .NET, Ms Access, Win (Windows App), VS 2008 (.NET 3.x)
Private Sub AutoCode()
Cm = New OleDbCommand("Select Max(ProductID)As ProCode From Product", Cn)
Dr.Read()
If NOT dr.HasRow Then
TextBox1.Text = "0001"
Else
Procode = Dr("Procode") + 1
Select Case Procode
Case Is < 10
TextBox1.Text = "000" & Procode
Case Is < 100
TextBox1.Text = "00" & Procode
Case Is < 1000
TextBox1.Text = "0" & Procode
Case Is < 10000
TextBox1.Text = Procode
End Select
End If
Cm = New OleDbCommand("select max (ProductID)As maxcode From Product", Cn)
Dr = Cm.ExecuteReader
Dr.Read()
If Dr("Maxcode") Is DBNull.Value Then
TextBox1.Text = "0001"
Else
Procode = Dr("Maxcode") + 1
Select Case Procode
Case Is < 10
TextBox1.Text = "000" & Procode
Case Is < 100
TextBox1.Text = "00" & Procode
Case Is < 1000
TextBox1.Text = "0" & Procode
Case Is < 10000
TextBox1.Text = Procode
End Select
End If
End Sub