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 7552271
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T10:43:07+00:00 2026-05-30T10:43:07+00:00

I know this question has been asked several times and I read those with

  • 0

I know this question has been asked several times and I read those with no luck 🙁 So I am asking it again with my code.

I have created a stored procedure to update a database table.

Stored procedure:

CREATE PROCEDURE usp_PettyCash_EditExpenseInfo 
(
    @ExpenseID bigint,
    @ExpenseName varchar(100),
    @SAPCode varchar(50),
    @MaxLimit decimal,
    @ExpenseType varchar(50)
)
AS
BEGIN 
    UPDATE t_ExpenseInfo 
    SET ExpenseName = @ExpenseName, 
        SAPCode = @SAPCode,       
        MaxLimit = @MaxLimit, 
        ExpenseType = @ExpenseType 
    WHERE 
        ExpenseID = @ExpenseID
END 
GO

But when I call this from code behind with below code, it gives the exception similar to

Error in converting from nvarchar to bigint

Code behind:

oOleDbCommand.Parameters.AddWithValue("@ExpenseName", oInputExpense.ExpenseName.ToString());
oOleDbCommand.Parameters.AddWithValue("@SAPCode", oInputExpense.SAPCode.ToString());
oOleDbCommand.Parameters.AddWithValue("@MaxLimit", Convert.ToDecimal(oInputExpense.MaxLimit));
oOleDbCommand.Parameters.AddWithValue("@ExpenseType", oInputExpense.ExpenseType.ToString());
oOleDbCommand.Parameters.AddWithValue("@ExpenseID", Convert.ToDouble(oInputExpense.ExpenseID.ToString()));

I also tried this:

oOleDbCommand.CommandText = "UPDATE t_ExpenseInfo SET ExpenseName='" + oInputExpense.ExpenseName.ToString() + "', SAPCode='" + oInputExpense.SAPCode.ToString() + "', MaxLimit=" + oInputExpense.MaxLimit + ", ExpenseType='" + oInputExpense.ExpenseType.ToString() + "' WHERE ExpenseID=" + oInputExpense.ExpenseID + "";

this DIRECT command runs OK from SQL Query Analyzer from from code behind this also give an “Access Violation” error.

I am really confused about what to do? Please 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-30T10:43:08+00:00Added an answer on May 30, 2026 at 10:43 am

    is there any particular reason why you’re using OleDbCommand instead of the “native” SQL Server SqlCommand ??

    I would try this:

    using(SqlConnection conn = new SqlConnection("(add your connection string here)"))
    using(SqlCommand cmd = new SqlCommand("dbo.usp_PettyCash_EditExpenseInfo", conn))
    {
       cmd.CommandType = CommandType.StoredProcedure;
    
       // add parameters with defined type!
       cmd.Parameters.Add("@ExpenseID", SqlDbType.BigInt).Value = .....;
       cmd.Parameters.Add("@ExpenseName", SqlDbType.VarChar, 100).Value = ".....";
       cmd.Parameters.Add("@SAPCode", SqlDbType.VarChar, 50).Value = ".....";
       cmd.Parameters.Add("@MaxLimit", SqlDbType.Decimal, 15, 2).Value = 100.00;
       cmd.Parameters.Add("@ExpenseType", SqlDbType.VarChar, 50).Value = "......";
    
       // open connection, call stored procedure, close connection
       conn.Open();
       cmd.ExecuteNonQuery();
       conn.Close();
    }
    

    Basically, I prefer using the native SqlConnection/SqlCommand over the old, legacy OleDb stuff, and I also prefer to explicitly specify what type my parameters are – don’t rely on ADO.NET or some other part figuring it out automagically – when it has to guess, it can get it wrong, and error like the one you see might occur. If you define it yourself, you’re in control!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know this question has been asked several times for sure, but I have
I know that this question has been asked several times and I've read all
I know this question has been asked several times, but I can't quite seem
Ok, so I know this question has been asked in different forms several times,
I know that this question have been asked several times. But I can't get
I know this question has been asked quite a few times, however, I have
I know this question has been asked many times and we have gotten this
I know this question has been asked several times on SO, but none of
First, I know this question has been asked several times before and that in
I know this question has been asked many times. But from what I read,

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.