Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

  • Administrators
Posted (edited)
You would need to prefix Catalog with it's namespace, however you seem to be putting it into the already existing System.dat.sqlclient namespace - is there a reason for this, usually you would want to extend the system provided namespaces in this manor. Edited by PlausiblyDamp

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...