> >Imports System.Data.SqlClient >Module CommonModule > Public dr As SqlDataReader > Public Function Selectdr(ByVal tablename As String, ByVal field As String, ByVal value As String, Optional ByVal tablename2 As String = "", Optional ByVal joinfield As String = "", Optional ByVal wherefield As String = "") As SqlDataReader > Dim conn As SqlConnection = GetConnection() > > Try > > > Dim sqlcmd As New SqlCommand("select * from syslib", conn) > End If > > conn.Open() > > Return sqlcmd.ExecuteReader < 'in this the compile display error > > Finally > conn.Close() > conn.Dispose() > End Try > End Function >End Module > > > > >Apart from the un-matched 'End If' that looks OK. NullReferenceException sounds more like a runtime exception- are you sure you see this at compile time?