Private Sub SearchAutoLotNo()
Dim ReadId As String = ""
Dim NewId As Integer = 0
Dim dtCountLot As New DataTable()
Dim CountLot As String = ""
Dim Sql As String = "SELECT Count_LotNo FROM StorkDLGB ORDER BY Count_LotNo DESC"
Com = New SqlCommand
With Conn
If .State = ConnectionState.Open Then .Close()
.ConnectionString = strConn
.Open()
End With
With Com
.CommandType = CommandType.Text
.CommandText = Sql
.Connection = Conn
dr = .ExecuteReader()
'dr.Read()
dtCountLot.Load(dr)
CountLot = dr.Item("Count_LotNo").ToString()
If CountLot = "" Then
TextBox1.Text = "01"
Else
NewId = CInt(CountLot) + 1
TextBox1.Text = NewId.ToString("00")
End If
'If dr.HasRows Then
'dtCountLot.Load(dr)
'CountLot = CountLot + 1
'TextBox1.Text = CountLot.ToString("00")
'Else
'TextBox1.Text = "01"
' dr.Read()
' ReadId = dr.Item("LotNo").ToString()
' NewId = CInt(ReadId) + 1
' TextBox1.Text = NewId.ToString("00")
'Else
' TextBox1.Text = "01"
'End If
End With
dr.Close()
Conn.Close()
End Sub
ช่วยดูให้หน่อยคับมันERROR อะคับ"Invalid attempt to call MetaData when reader is closed."