Accessing a method within a class VB.NET from a Web Form page.

 I got the following class within my App_Code folder under a file called DataAccess.vb:

  Namespace CircaComArtAccess

Public Class ComArtData

Private _connstr As String = System.Configuration.ConfigurationManager.ConnectionStrings("ESQLConn").ConnectionString()

Public Sub ComArtGrid(ByVal procedurename As String, _
ByVal parameters() As SqlParameter, _
ByVal gridname As ComponentArt.Web.UI.Grid, _
ByVal e As ComponentArt.Web.UI.CallBackEventArgs, _
Optional ByVal commandtype As CommandType = 1 _
)
Dim SQLConn As SqlConnection
SQLConn = New SqlConnection(_connstr)

Dim cmd As SqlCommand = New SqlCommand(procedurename, SQLConn)
Dim dt As New DataTable

Try
dt.Load(cmd.ExecuteReader)

With gridname
.DataSource = dt
.DataBind()
.RenderControl(e.Output)
End With

Catch ex As Exception

End Try

End Sub

End Class

            
 I am trying to access the method  "ComArtGrid" from my class within a web form page but cant figure out how to access it.

            
 

            
 
 

Victor A. Palma
Imports CircaComArtAccess

Partial Class vptest_testClass
    Inherits System.Web.UI.Page

    Dim BindData As ComArtData

    BindData.???

End Class
  Any suggestions?
0
vicpal25
3/15/2007 8:37:39 PM
📁 asp.net.getting-started
📃 91979 articles.
⭐ 4 followers.

💬 7 Replies
👁️‍🗨️ 1517 Views



            

 You have to first initialize the BindData variable to access any of its method's, properties etc. 

            
Dim BindData As New ComArtData()
BindData.ComArtGrid("procedurename", New SqlParameter() {}, _
  myGrid, e)
' In the above e stands for ComponentArt.Web.UI.CallBackEventArgs

          
0
codeasp
3/15/2007 8:50:31 PM
Thats what I've been trying to do but I get a blue underline error under my BindData that says "Declaration Expected". ????


Victor A. Palma
0
vicpal25
3/15/2007 8:56:08 PM

Try this, see if it helps.
dim BindData as New CircaComArtAccess.ComArtData()
 
0
codeasp
3/15/2007 9:03:53 PM
 No luck:

    Dim BindData As New CircaComArtAccess.ComArtData()


    BindData.ComArtGrid("csp_shipment_stat_qry", New SqlParameter(), GridView1)
'  --------- blue line "declaration expected" 
' its already declared! 
 Funny thing that is already declared. Anything wrong with my class? seems okay to me.

Victor A. Palma
0
vicpal25
3/15/2007 9:53:03 PM

Try this.
dim BindData as CircaComArtAccess.ComArtData
sub Page_Load(sender, e)
   If Not IsPostback Then
      BindData = New CircaComArtAccess.ComArtData()
      BindData.ComArtGrid(signature of the method)
   End If
end sub
 
0
codeasp
3/15/2007 9:59:57 PM

That seems to do it. You have to declare it a global variable rather then local, hummm. The second local declaration is not needed:
    Dim BindData As CircaComArtAccess.ComArtData

    Sub Page_Load(ByVal sender, ByVal e)
        If Not IsPostBack Then
            BindData.ComArtGrid(parameters from function)
        End If
    End Sub

            
Awesome job! <img src="http://forums.asp.net/emoticons/emotion-4.gif" alt="Stick out tongue"> 
  

Victor A. Palma
0
vicpal25
3/15/2007 10:07:17 PM
Well you do not have to declare it as global variable.  You can declare and initialize it in the page_load event itself.  Glad it worked for you.
0
codeasp
3/15/2007 10:13:27 PM
Reply: