Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6715291
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:35:50+00:00 2026-05-26T08:35:50+00:00

I’ve run into a rather annoying problem which I cannot seem to get to

  • 0

I’ve run into a rather annoying problem which I cannot seem to get to the root of.
I’ve searched the internet for similar problems – and I’ve found a few unanswered in other forums – so I thought I’d give it a go here.

The following WebMethod of a webservice contacts a database, which works fine, and runs a stored procedure.

The problem is, that when I pass the parameters as single characters it tells me it cannot find either of the parameters and when I pass a full length “ean” parameter it tells me the following error message:

System.Data.OleDb.OleDbException: Error converting data type varchar to int.
   at System.Data.OleDb.OleDbDataReader.ProcessResults(OleDbHResult hr)
   at System.Data.OleDb.OleDbDataReader.NextResult()
   at System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method)
   at System.Data.OleDb.OleDbCommand.ExecuteReader(CommandBehavior behavior)
   at System.Data.OleDb.OleDbCommand.ExecuteReader()
   at Service.GetOthersRatings(Int32 personID, String ean)

And now here’s the Webmethod:

[WebMethod(Description = "GetRatings")]
public string GetRatings(int personID, string ean)
{
    string ratings = "";
    OleDbConnection connection = new OleDbConnection(connectionString);
    OleDbCommand command = new OleDbCommand("GetRatings", connection);
    command.CommandType = CommandType.StoredProcedure;
    command.Parameters.Add("@personID",OleDbType.Integer,10).Value = personID;
    command.Parameters.Add("@ean",OleDbType.VarChar,30).Value = ean;
    try
    {
        connection.Open();
        myReader = command.ExecuteReader();
        if (myReader.HasRows)
        {
            while (myReader.Read())
            {
                ratings = myReader.GetString(0);
            }
        }
        else
        {
            ratings = "Null";
        }
    }
   catch (Exception e)
    {
        ratings = "Error - " + e.ToString();
    }
    finally
    {
    }
    return ratings;
}

One thing that’s worth mentioning is that if I remove the OUTPUT part of the SP, it runs fine down to and returns

    ratings = "Null";

But seeing that I try to read a String from the reader, I don’t see why it wouldn’t work with a varchar output from the SP.

In the Database we have the corresponding Stored Procedure, which works fine if just executed in SQL Server Management Studio:

IF ( OBJECT_ID('GetRatings') IS NOT NULL ) 
DROP PROCEDURE GetRatings
GO

CREATE PROCEDURE GetRatings
    @ratingschars           varchar(36) = NULL OUTPUT,
    @personID               int,
    @ean                    varchar(30)

AS
BEGIN TRAN
SET NOCOUNT ON;
    BEGIN
    DECLARE @pris varchar(2)
    DECLARE @forventet varchar(2)
    DECLARE @smag varchar(2)
    DECLARE @count varchar(30)

    IF EXISTS(SELECT * FROM feedback where personID = @personID AND ean = @ean)
        BEGIN 
            SELECT @pris = (SELECT CAST(pris AS varchar(2)) FROM feedback   where personID = @personID AND ean = @ean)
            SELECT @forventet = (SELECT CAST(forventet AS varchar(2)) FROM feedback where personID = @personID AND ean = @ean)
            SELECT @smag = (SELECT CAST(smag AS varchar(2)) FROM feedback where personID = @personID AND ean = @ean)
            SELECT @ratingschars = @pris + @forventet + @smag
        END
    ELSE
        BEGIN
            SELECT @pris = (SELECT CAST(avg(pris) AS varchar(2)) FROM feedback WHERE ean = @ean)
            SELECT @forventet += (SELECT CAST(avg(forventet) AS varchar(2)) FROM feedback WHERE ean = @ean)
            SELECT @smag += (SELECT CAST(avg(smag) AS varchar(2)) FROM feedback WHERE ean = @ean)
            SELECT @count += (SELECT CAST(count(*) AS varchar(30)) FROM feedback WHERE ean = @ean)
            SELECT @ratingschars = @pris + @forventet + @smag + @count
        END
    END
COMMIT TRAN

Which I’ve tried to change to output of to int, with the same error results.
I’m stumped – I need help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T08:35:51+00:00Added an answer on May 26, 2026 at 8:35 am

    Stored-procedure has three parameters where as in your code, you’ve added only two parameters. So add a third parameter as OutPut type.

    EDIT:

    Stored Procedure:

    ALTER PROCEDURE SampleProc
    
    @no1 int,
    @no2 int,
    @result int OUTPUT
    AS
      set @result=@no1+@no2
    RETURN
    

    Code to execute the Stored-procedure:

    cmd.CommandText = "SampleProc"
    cmd.CommandType = CommandType.StoredProcedure
    cmd.Connection = cn
    
    Dim no1 as New OleDbParameter("@no1", OleDbType.Integer)
    Dim no2 as New OleDbParameter("@no2", OleDbType.Integer)
    Dim resultas New OleDbParameter("@result", OleDbType.Integer)
    result.Direction = ParameterDirection.Output
    
    no1.Value = 10
    no2.Value = 20
    
    cmd.Parameters.Add(no1)
    cmd.Parameters.Add(no2)
    cmd.Parameters.Add(result)
    
    cn.Open()
    cmd.ExecuteNonQuery()
    cn.Close()
    
    Dim returnResult as Integer 
    returnResult=CType(result.Value,Integer)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am currently running into a problem where an element is coming back from
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
this is what i have right now Drawing an RSS feed into the php,
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.