Use any of following options to check
DBNull
value:
Option1: Use sqlserver
IsNull()
function
Dim i As Integer
sql = "select isnull(max(p_id), 0) from tbl_product"
If rs.State = 1 Then rs.Close()
rs.Open(sql, conn)
If rs.EOF = False Then
i = rs(0).Value
i = i + 1
txtid.Text = i
End If
Option2: Use
DBNull.Value
in vb
Dim i As Integer
sql = "select max(p_id) from tbl_product"
If rs.State = 1 Then rs.Close()
rs.Open(sql, conn)
If rs.EOF = False Then
i = If((rs(0).Value = DBNull.Value), 0, Convert.ToInt32(rs(0).Value))
i = i + 1
txtid.Text = i
End If