By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,680 Members | 1,486 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,680 IT Pros & Developers. It's quick & easy.

problem with OleDbParameter

P: n/a
Hi

I am trying to follow the walkthrough on MSDN
http://msdn.microsoft.com/library/en...InWebForms.asp

however, as I do not have a working version of SQL server available (which
is another story . . ) I have tried to modify the code to use OLEconnection
and OLECommand with the Jet 4.0 data link provider.

The connection seems to work OK - the page loads with the first record of
the dataset. However when I select the category ID of any other item, I get
this error:

An OleDbParameter with ParameterName 'categoryid' is not contained by this
OleDbParameterCollection.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information about
the error and where it originated in the code.

Exception Details: System.IndexOutOfRangeException: An OleDbParameter with
ParameterName 'categoryid' is not contained by this OleDbParameterCollection.

Source Error:
Line 91: Categoryid = ddlCategoryID.SelectedItem.Text
Line 92:
Line 93: cmdCategoriesByID.Parameters("categoryid").Value = Categoryid
Line 94:
Line 95: OleDbConnection1.Open()

Here is the full code for what I guess is the relevant bit:

Private Sub ddlCategoryID_SelectedIndexChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
ddlCategoryID.SelectedIndexChanged

Dim Categoryid As String
Categoryid = ddlCategoryID.SelectedItem.Text

cmdCategoriesByID.Parameters("categoryid").Value = Categoryid

OleDbConnection1.Open()
Dim dReader As System.Data.OleDb.OleDbDataReader
dreader = cmdCategoriesByID.ExecuteReader(CommandBehavior.Si ngleRow)
If dreader.Read() Then
txtCategoryName.Text = dreader(1)
txtCategoryDescription.Text = dreader(2)
End If
dreader.Close()
OleDbConnection1.Close()

End Sub

Anyone have any thoughts on why it won't work?

Thanks.
--
one door shuts, another closes . .
Jul 21 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
this:
cmdCategoriesByID.Parameters("categoryid").Value = Categoryid

should be this:
cmdCategoriesByID.Parameters("@categoryid").Value = Categoryid

Greg

"TattyMane bigpond.net.au>" <dale1229@<deletethis> wrote in message
news:E1**********************************@microsof t.com...
Hi

I am trying to follow the walkthrough on MSDN :
http://msdn.microsoft.com/library/en...InWebForms.asp

however, as I do not have a working version of SQL server available (which
is another story . . ) I have tried to modify the code to use
OLEconnection
and OLECommand with the Jet 4.0 data link provider.

The connection seems to work OK - the page loads with the first record of
the dataset. However when I select the category ID of any other item, I
get
this error:

An OleDbParameter with ParameterName 'categoryid' is not contained by this
OleDbParameterCollection.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about
the error and where it originated in the code.

Exception Details: System.IndexOutOfRangeException: An OleDbParameter with
ParameterName 'categoryid' is not contained by this
OleDbParameterCollection.

Source Error:
Line 91: Categoryid = ddlCategoryID.SelectedItem.Text
Line 92:
Line 93: cmdCategoriesByID.Parameters("categoryid").Value =
Categoryid
Line 94:
Line 95: OleDbConnection1.Open()

Here is the full code for what I guess is the relevant bit:

Private Sub ddlCategoryID_SelectedIndexChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
ddlCategoryID.SelectedIndexChanged

Dim Categoryid As String
Categoryid = ddlCategoryID.SelectedItem.Text

cmdCategoriesByID.Parameters("categoryid").Value = Categoryid

OleDbConnection1.Open()
Dim dReader As System.Data.OleDb.OleDbDataReader
dreader =
cmdCategoriesByID.ExecuteReader(CommandBehavior.Si ngleRow)
If dreader.Read() Then
txtCategoryName.Text = dreader(1)
txtCategoryDescription.Text = dreader(2)
End If
dreader.Close()
OleDbConnection1.Close()

End Sub

Anyone have any thoughts on why it won't work?

Thanks.
--
one door shuts, another closes . .

Jul 21 '05 #2

P: n/a
Tatty,

Because there is already a message from Greg, I don't add more than the part
where you are talking about SQL server. Did you know that there is a free
SQL server online (very stripped) it has limits, however for testing it is
very fine, it acts basicly the same as SQL server.

It is a hell of a job to install it when your computer uses not Strongly
Typed Password and as well the route to use it in an aspnet environment is
the same hell.

There is told that this will be fore the next version better.

http://www.microsoft.com/downloads/d...DisplayLang=en
http://msdn.microsoft.com/library/de...eddingmsde.asp
http://www.informit.com/isapi/produc...t/articlex.asp
I hope this helps a little bit?

Cor
Jul 21 '05 #3

P: n/a
Greg:

Thanks. However, if I try to use the '@' in the query builder , I get an
error: 'data type error in expression. It will only allow '=categoryid'.
ie:
SELECT CategoryID, CategoryName, Description
FROM Categories
WHERE (CategoryID = CategoryID)

If I use the '@categorid' in the code, I get the same error as before.
Apparentlythe "@" prefix is required for SQL Server named parameters.

?

David

"Greg Burns" wrote:
this:
cmdCategoriesByID.Parameters("categoryid").Value = Categoryid

should be this:
cmdCategoriesByID.Parameters("@categoryid").Value = Categoryid

Greg

"TattyMane bigpond.net.au>" <dale1229@<deletethis> wrote in message
news:E1**********************************@microsof t.com...
Hi

I am trying to follow the walkthrough on MSDN :
http://msdn.microsoft.com/library/en...InWebForms.asp

however, as I do not have a working version of SQL server available (which
is another story . . ) I have tried to modify the code to use
OLEconnection
and OLECommand with the Jet 4.0 data link provider.

The connection seems to work OK - the page loads with the first record of
the dataset. However when I select the category ID of any other item, I
get
this error:

An OleDbParameter with ParameterName 'categoryid' is not contained by this
OleDbParameterCollection.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about
the error and where it originated in the code.

Exception Details: System.IndexOutOfRangeException: An OleDbParameter with
ParameterName 'categoryid' is not contained by this
OleDbParameterCollection.

Source Error:
Line 91: Categoryid = ddlCategoryID.SelectedItem.Text
Line 92:
Line 93: cmdCategoriesByID.Parameters("categoryid").Value =
Categoryid
Line 94:
Line 95: OleDbConnection1.Open()

Here is the full code for what I guess is the relevant bit:

Private Sub ddlCategoryID_SelectedIndexChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
ddlCategoryID.SelectedIndexChanged

Dim Categoryid As String
Categoryid = ddlCategoryID.SelectedItem.Text

cmdCategoriesByID.Parameters("categoryid").Value = Categoryid

OleDbConnection1.Open()
Dim dReader As System.Data.OleDb.OleDbDataReader
dreader =
cmdCategoriesByID.ExecuteReader(CommandBehavior.Si ngleRow)
If dreader.Read() Then
txtCategoryName.Text = dreader(1)
txtCategoryDescription.Text = dreader(2)
End If
dreader.Close()
OleDbConnection1.Close()

End Sub

Anyone have any thoughts on why it won't work?

Thanks.
--
one door shuts, another closes . .


Jul 21 '05 #4

P: n/a
Thanks Cor.

I had a SQLExpress up but not running: a TCP/IP problem apparently. When I
(maybe) fixed that, it would not re-install. I shall try the download you've
suggested.

David

"Cor Ligthert" wrote:
Tatty,

Because there is already a message from Greg, I don't add more than the part
where you are talking about SQL server. Did you know that there is a free
SQL server online (very stripped) it has limits, however for testing it is
very fine, it acts basicly the same as SQL server.

It is a hell of a job to install it when your computer uses not Strongly
Typed Password and as well the route to use it in an aspnet environment is
the same hell.

There is told that this will be fore the next version better.

http://www.microsoft.com/downloads/d...DisplayLang=en
http://msdn.microsoft.com/library/de...eddingmsde.asp
http://www.informit.com/isapi/produc...t/articlex.asp
I hope this helps a little bit?

Cor

Jul 21 '05 #5

P: n/a
Tatty,

There are two desctiptions of the OleDb parameter on MSDN, this one is what
you get in a normal search

http://msdn.microsoft.com/library/de...classtopic.asp

This one is as it should be in my opinion

http://msdn.microsoft.com/library/de...eterstopic.asp

I hope this helps?

Cor
Jul 21 '05 #6

P: n/a
Cor

'fraid not - probably because I have too little understanding of the subject
matter. I shall try the SQL server download and hopefully that will work.

thanks once again.

David.

"Cor Ligthert" wrote:
Tatty,

There are two desctiptions of the OleDb parameter on MSDN, this one is what
you get in a normal search

http://msdn.microsoft.com/library/de...classtopic.asp

This one is as it should be in my opinion

http://msdn.microsoft.com/library/de...eterstopic.asp

I hope this helps?

Cor

Jul 21 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.