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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T02:04:27+00:00 2026-06-09T02:04:27+00:00

I use Enterprise Library and I have one problem: string sql = UPDATE StackOverflow

  • 0

I use Enterprise Library and I have one problem:

string sql = " 
               UPDATE StackOverflow SET UserName = @UserName
               WHERE Id = @Id 
             ";

DbCommand cmd = base.Database.GetSqlStringCommand(sql);

base.Database.AddInParameter(cmd, "Id", DbType.Int32, StackOverflow.Id);
base.Database.AddInParameter(cmd, "UserName", DbType.Int32, StackOverflow.UserName);

int val = Convert.ToInt32(base.Database.ExecuteScalar(cmd));

Convert.ToInt32(base.Database.ExecuteScalar(cmd)) //returns 0.

I’ve read this article http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlcommand.executescalar.aspx

The article says:
The function returns the new Identity column value if a new row was inserted, 0 on failure.

but I did not insert into that table – I only want to update and return updated row Id.

  • 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-06-09T02:04:29+00:00Added an answer on June 9, 2026 at 2:04 am

    You should use ExecuteNonQuery in your case.

    ExecuteScalar

    Executes the query, and returns the first column of the first row in the result set returned by the query

    ExecuteNonQuery

    Executes a Transact-SQL statement against the connection and returns the number of rows affected

    Your query doesn’t return anything, so ExecuteScalar is not the right method to work with.
    ExecuteNonQuery on the other side will give the correct information if your query has updated anything.

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

Sidebar

Related Questions

I have about 50 web-sites, load-balanced across 5 web-servers. They all use Enterprise Library
We use Enterprise Library 3.0 to access Oracle DB (microsoft oracle client). What happens
How can I use Enterprise Library to do a Data Access Layer in c#
I'm attempting to use the DatabaseFactory method from the Microsoft Enterprise Library. using Microsoft.Practices.EnterpriseLibrary.Data;
Does MS have a sample enterprise application that demonstrates the use of different Enterprise
Is it possible to use the Enterprise Library 4.1 TraceListeners without using the entire
Using .NET 2.0, C#, Windows Forms development, Enterprise Library 3.1. We have a project
I am an asp.net web application developer and I always have used Enterprise Library
Can anyone tell me why i should use the Enterprise library Data application block
I'm trying to use the Common Infrastructure Libraries for .NET (Common.Logging) with Enterprise Library

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.