473,387 Members | 1,899 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Access QueryString value in a UserControl

I've created a user control that extracts data from a database.
The VB code is all contained in a code-behind file.

I'm trying to extract a value from the request.querystring but keep getting
the following error:

Description: An error occurred during the compilation of a resource required
to service this request. Please review the following specific error details
and modify your source code appropriately.

Compiler Error Message: BC30369: Cannot refer to an instance member of a
class from within a shared method or shared member initializer without an
explicit instance of the class.

Source Error:
Line 40:
Line 41: dim ParaCategory as new oledbParameter
Line 42: ParaCategory.Value=request.querystring("CatID")
Line 43: ParaCategory.ParameterName="@Cat"
Line 44: ParaCategory.dbType=dbType.Int32

I'm very new to this so I've probably made a really simple mistake.
I have the following imports at in my code.

Imports System
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Data
Imports System.Data.OleDB
Imports System.Web

Which class is the Error referring to?
Any help would be greatly appreciated.

Thanks
Nick
Nov 19 '05 #1
3 5338
You have two types of methods and properties. The first are class
methods/properties, which are Shared or static. The second are instance
methods/properties, which require you to create an object from your class to
access them.

I do not see the code where you are pulling the item from Request, but this
is where I would look. You may have the applicaiton set up where it requires
instantiating the Request object before pulling items from it. Post a bit
more code to get a more specific answer.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***************************
Think Outside the Box!
***************************
"Nick" wrote:
I've created a user control that extracts data from a database.
The VB code is all contained in a code-behind file.

I'm trying to extract a value from the request.querystring but keep getting
the following error:

Description: An error occurred during the compilation of a resource required
to service this request. Please review the following specific error details
and modify your source code appropriately.

Compiler Error Message: BC30369: Cannot refer to an instance member of a
class from within a shared method or shared member initializer without an
explicit instance of the class.

Source Error:
Line 40:
Line 41: dim ParaCategory as new oledbParameter
Line 42: ParaCategory.Value=request.querystring("CatID")
Line 43: ParaCategory.ParameterName="@Cat"
Line 44: ParaCategory.dbType=dbType.Int32

I'm very new to this so I've probably made a really simple mistake.
I have the following imports at in my code.

Imports System
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Data
Imports System.Data.OleDB
Imports System.Web

Which class is the Error referring to?
Any help would be greatly appreciated.

Thanks
Nick

Nov 19 '05 #2
Hi Gregory
Here is my complete code from the code behind file for my user control

Imports System
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Data
Imports System.Data.OleDB
Imports System.Web

Namespace PS

Public Class CategoryList
Inherits UserControl

public RepDocs as DataList
sub Page_load (o as Object, E as eventargs) handles mybase.Load
RenderMenu
end sub

sub RenderMenu

repDocs.DataSource=MyQueryMethod()
repDocs.DataBind()
end sub
shared Function MyQueryMethod() As OleDBDataReader
Dim connectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;
Ole DB Services=-4; Data
Source=C:\InetPub\wwwroot\PersonnelSolutions\Data\ documents.mdb"
Dim dbConnection As New OleDbConnection(connectionString)

Dim queryString As String
Dim dbCommand As New OleDbCommand

QueryString= "SELECT [DocId], [DocName], [DocDescription],
[Price],[DocCategory] FROM [tDocuments] " _
& "WHERE [DocCategory]=@Cat"

dbCommand.CommandText = queryString
dbCommand.Connection = dbConnection
dim ParaCategory as new oledbParameter
ParaCategory.Value=request.querystring("CatID") '**** this is the
error line ****
ParaCategory.ParameterName="@Cat"
ParaCategory.dbType=dbType.Int32

dbCommand.Parameters.Add(ParaCategory)

dbConnection.Open
Dim dataReader As OleDBDataReader =
dbCommand.ExecuteReader(System.Data.CommandBehavio r.CloseConnection)

Return dataReader
End Function
End Class

End Namespace

I think I understand what you mean regarding the different types of
methods/properties to to be honest I don't which object I to to instantiate
to create teh Request object. Dim (ing) an new Request object also throws an
error.

Thanks in advance
Nick

"Cowboy (Gregory A. Beamer) - MVP" <No************@comcast.netNoSpamM> wrote
in message news:91**********************************@microsof t.com...
You have two types of methods and properties. The first are class
methods/properties, which are Shared or static. The second are instance
methods/properties, which require you to create an object from your class
to
access them.

I do not see the code where you are pulling the item from Request, but
this
is where I would look. You may have the applicaiton set up where it
requires
instantiating the Request object before pulling items from it. Post a bit
more code to get a more specific answer.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***************************
Think Outside the Box!
***************************
"Nick" wrote:
I've created a user control that extracts data from a database.
The VB code is all contained in a code-behind file.

I'm trying to extract a value from the request.querystring but keep
getting
the following error:

Description: An error occurred during the compilation of a resource
required
to service this request. Please review the following specific error
details
and modify your source code appropriately.

Compiler Error Message: BC30369: Cannot refer to an instance member of a
class from within a shared method or shared member initializer without an
explicit instance of the class.

Source Error:
Line 40:
Line 41: dim ParaCategory as new oledbParameter
Line 42: ParaCategory.Value=request.querystring("CatID")
Line 43: ParaCategory.ParameterName="@Cat"
Line 44: ParaCategory.dbType=dbType.Int32

I'm very new to this so I've probably made a really simple mistake.
I have the following imports at in my code.

Imports System
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Data
Imports System.Data.OleDB
Imports System.Web

Which class is the Error referring to?
Any help would be greatly appreciated.

Thanks
Nick

Nov 19 '05 #3
DOH !!!!

What an idiot I am..
I had the keyword SHARED in front of my function (which is only for internal
use by the class).
I removed this and all works...

Nick

"Nick" <ni**@NoSpam.co.uk> wrote in message
news:O4**************@TK2MSFTNGP15.phx.gbl...
Hi Gregory
Here is my complete code from the code behind file for my user control

Imports System
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Data
Imports System.Data.OleDB
Imports System.Web

Namespace PS

Public Class CategoryList
Inherits UserControl

public RepDocs as DataList
sub Page_load (o as Object, E as eventargs) handles mybase.Load
RenderMenu
end sub

sub RenderMenu

repDocs.DataSource=MyQueryMethod()
repDocs.DataBind()
end sub
shared Function MyQueryMethod() As OleDBDataReader
Dim connectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;
Ole DB Services=-4; Data
Source=C:\InetPub\wwwroot\PersonnelSolutions\Data\ documents.mdb"
Dim dbConnection As New OleDbConnection(connectionString)

Dim queryString As String
Dim dbCommand As New OleDbCommand

QueryString= "SELECT [DocId], [DocName], [DocDescription],
[Price],[DocCategory] FROM [tDocuments] " _
& "WHERE [DocCategory]=@Cat"

dbCommand.CommandText = queryString
dbCommand.Connection = dbConnection
dim ParaCategory as new oledbParameter
ParaCategory.Value=request.querystring("CatID") '**** this is the
error line ****
ParaCategory.ParameterName="@Cat"
ParaCategory.dbType=dbType.Int32

dbCommand.Parameters.Add(ParaCategory)

dbConnection.Open
Dim dataReader As OleDBDataReader =
dbCommand.ExecuteReader(System.Data.CommandBehavio r.CloseConnection)

Return dataReader
End Function
End Class

End Namespace

I think I understand what you mean regarding the different types of
methods/properties to to be honest I don't which object I to to
instantiate to create teh Request object. Dim (ing) an new Request object
also throws an error.

Thanks in advance
Nick

"Cowboy (Gregory A. Beamer) - MVP" <No************@comcast.netNoSpamM>
wrote in message
news:91**********************************@microsof t.com...
You have two types of methods and properties. The first are class
methods/properties, which are Shared or static. The second are instance
methods/properties, which require you to create an object from your class
to
access them.

I do not see the code where you are pulling the item from Request, but
this
is where I would look. You may have the applicaiton set up where it
requires
instantiating the Request object before pulling items from it. Post a bit
more code to get a more specific answer.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***************************
Think Outside the Box!
***************************
"Nick" wrote:
I've created a user control that extracts data from a database.
The VB code is all contained in a code-behind file.

I'm trying to extract a value from the request.querystring but keep
getting
the following error:

Description: An error occurred during the compilation of a resource
required
to service this request. Please review the following specific error
details
and modify your source code appropriately.

Compiler Error Message: BC30369: Cannot refer to an instance member of a
class from within a shared method or shared member initializer without
an
explicit instance of the class.

Source Error:
Line 40:
Line 41: dim ParaCategory as new oledbParameter
Line 42: ParaCategory.Value=request.querystring("CatID")
Line 43: ParaCategory.ParameterName="@Cat"
Line 44: ParaCategory.dbType=dbType.Int32

I'm very new to this so I've probably made a really simple mistake.
I have the following imports at in my code.

Imports System
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Data
Imports System.Data.OleDB
Imports System.Web

Which class is the Error referring to?
Any help would be greatly appreciated.

Thanks
Nick


Nov 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Masterblue | last post by:
Hi, Right know im teaching myself a little about CDONTS . But know I want to sent data form a database with a form. I wou ld like to do the following: - I have made a page with set of records....
3
by: Paul | last post by:
Hi all, at present I I've built a website which can be updated by admin and users. My problem, I've combined "log in" and "access levels" to restrict access to certain pages, using the built...
0
by: Matt Howeson | last post by:
Some time ago I posted a request for help with a problem I was having sometime ago whereby a 404 error would result if any access to the Querystring had been made before the Context.Rewritepath is...
0
by: darrel | last post by:
This is an odd question I'll try to word as best as I can. I have an ASPX page. Two of the userControls check the queryString and response.write a value to me for testing. One userControl is...
5
by: c676228 | last post by:
Hi, I guess I am confused. In aspx script, I mean (you won't use Codebehind="enrollinfo.aspx.vb", but mix code with html and code together) You can access user control's property directly. Since I...
5
by: Paul | last post by:
I have a MasterPage that has on it several UserControls (*ascx files). I wish to control the visibility of the controls on the content pages according to some parameter (for example on a user...
1
by: Rico | last post by:
I have tried to access a database using asp.net. after some entries like 120+, I got an unspecified error message. Anyone know what is happening, it seems to be stuck at the same line even when i...
9
by: Alexander van Doormalen | last post by:
I have a situation that user controls are dynamically loaded within a page. To know which control to 're-add' to the page I saved the control path in the ViewState. This Control is added using...
3
by: =?Utf-8?B?R1ROMTcwNzc3?= | last post by:
Hi there, I've got the standard Dreamweaver restrict access to page behaviour below – <% ' *** Restrict Access To Page: Grant or deny access to this page MM_authorizedUsers="1,2,3"...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.