VB.NET & IsDBNull() - IsDBNull() : Returns a Boolean value indicating whether an expression evaluates to the System.DBNull class.
ShotDev Focus:
- VB.NET & IsDBNull()
Example
IsDBNull.aspx
<%@ Page Language="VB" %> <%@ import Namespace="System.Data" %> <%@ import Namespace="System.Data.OleDb" %> <script runat="server"> Sub Page_Load(sender As Object, e As EventArgs) Dim strConnString As String Dim objConn As OledbConnection strConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="&Server.MapPath("shotdev/mydatabase.mdb")&";Jet OLEDB:Database Password=;" objConn = New OleDbConnection(strConnString) objConn.Open() Dim dtAdapter As OleDbDataAdapter Dim dt As New DataTable Dim strSQL As String strSQL = "SELECT * FROM customer WHERE CustomerID = 'C003' " dtAdapter = New OleDbDataAdapter(strSQL, objConn) dtAdapter.Fill(dt) If dt.Rows.Count > 0 Then IF NOT IsDBNull(dt.Rows(0)("Name")) Then Me.lblText.Text = dt.Rows(0)("Name") End IF End IF objConn.Close() objConn = Nothing End Sub </script> <html> <head> <title>ShotDev.Com Tutorial</title> </head> <body> <form runat="server"> <asp:Label id="lblText" runat="server"></asp:Label> </form> </body> </html>
Screenshot