tbcmartinharvey
Newcomer
- Joined
- Oct 7, 2005
- Messages
- 10
I would really be grateful for some help.
I realize this is probably a very basic question but can someone tell me how
to do this. I have created a class function that uses a stored procedure to return a datareader. (I am using webmatrix)
I want to bind this datareader to a datagrid. I have been using dg.datasource=classfunctionnname" but I get a compile error saying the class function hasnt been declared.
I have included the the class function below:
Namespace System.Data.SqlClient
Public Class Catalog
Public Shared Function SP_GetBB() As SqlDataReader
Dim Connection as New SqlConnection(ConnectionString)
Dim command As New SqlCommand(CommandText,Connection)
Dim CommandText As String = "SP_GetBB"
Command.CommandType = CommandType.StoredProcedure
Connection.Open()
Return Command.ExecuteReader(CommandBehaviour.CloseConnection)
End Function
Private Shared ReadOnly Property connectionString() As String
Get
Return ConfigurationSettings.AppSettings("ConnectionString")
End Get
End Property
End Class
End Namespace
I have tried
Dim dr1 As SqlClient.SqlDataReader = Catalog.SP_GetBB
dg.datasource = dr1
But no combination I try seems to work.
I was wondering if this is a namespace problem
Scott Mitchell wrote that you cannot use the web.config Appsettings unless you include the relevant namespaces in the page.
http://aspnet.4guysfromrolla.com/articles/122403-1.aspx Maybe class functions are the same.
If anyone could hellp me i would be grateful
I realize this is probably a very basic question but can someone tell me how
to do this. I have created a class function that uses a stored procedure to return a datareader. (I am using webmatrix)
I want to bind this datareader to a datagrid. I have been using dg.datasource=classfunctionnname" but I get a compile error saying the class function hasnt been declared.
I have included the the class function below:
Namespace System.Data.SqlClient
Public Class Catalog
Public Shared Function SP_GetBB() As SqlDataReader
Dim Connection as New SqlConnection(ConnectionString)
Dim command As New SqlCommand(CommandText,Connection)
Dim CommandText As String = "SP_GetBB"
Command.CommandType = CommandType.StoredProcedure
Connection.Open()
Return Command.ExecuteReader(CommandBehaviour.CloseConnection)
End Function
Private Shared ReadOnly Property connectionString() As String
Get
Return ConfigurationSettings.AppSettings("ConnectionString")
End Get
End Property
End Class
End Namespace
I have tried
Dim dr1 As SqlClient.SqlDataReader = Catalog.SP_GetBB
dg.datasource = dr1
But no combination I try seems to work.
I was wondering if this is a namespace problem
Scott Mitchell wrote that you cannot use the web.config Appsettings unless you include the relevant namespaces in the page.
http://aspnet.4guysfromrolla.com/articles/122403-1.aspx Maybe class functions are the same.
If anyone could hellp me i would be grateful