Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How can I return SqlDataReader in Module
Message
De
20/05/2011 06:24:19
 
 
À
20/05/2011 05:18:30
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Versions des environnements
Environment:
VB 9.0
OS:
Windows XP
Database:
MS SQL Server
Application:
Desktop
Divers
Thread ID:
01511205
Message ID:
01511211
Vues:
42
>Hi all,
> i want to wirte a fucntion to return SqlDataReader in Module, but appear error, NullReferenceException was unhandled by user code.
>And Troubleshooting tips: Use the "new" keyword to create an object instance.
>I use vb.net , my table more data not nul,GetConnection is no problem , Anyone can give some idea to me , thank you .
>
>
>
>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?
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform