Friday, May 27, 2011

How to check from your Vb6 code if your Access database returns an empty string.

Sometimes if you are connecting to an Access DB , you may need to find if some field value is empty and perform some function on the basis of it .You may use the IsNull function to find if the field is empty in the db.

Dim cn As New ADODB.Connection
 cn.CursorLocation = adUseClient
 cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\stduser\Desktop\db1.mdb;Persist Security Info=False"

 Dim sql As New ADODB.Command
 sql.ActiveConnection = cn
 sql.CommandText = "Select City from Table1 where Country=" & "'" & Me.Field1.Text & "'"

 Dim rec As New ADODB.Recordset
 rec.Open sql

 If IsNull(rec.Fields(0).Value) Then
    -------  
Else
   ------------  
 End If

No comments:

Post a Comment