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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T17:05:39+00:00 2026-05-23T17:05:39+00:00

UPDATE 1: Does this look right? Dim objSqlConnection As SqlConnection Dim objSqlCommand As SqlCommand

  • 0

UPDATE 1:

Does this look right?

Dim objSqlConnection As SqlConnection
Dim objSqlCommand As SqlCommand

Dim intAffectedRowCount As Integer

Function update_function() As Integer
    Using objSqlConnection = New SqlConnection(System.Configuration.ConfigurationManager.AppSettings("connectionString"))
        objSqlCommand = New SqlCommand("update table1 set col1 = @col1 where id = @id", objSqlConnection)

        objSqlCommand.Parameters.Add("@col1", SqlDbType.VarChar, 255).Value = strData
        objSqlCommand.Parameters.Add("@id", SqlDbType.Int, 4).Value = intID

        objSqlCommand.Connection.Open()
        intAffectedRowCount = objSqlCommand.ExecuteNonQuery()
        objSqlCommand.Connection.Close()
    End Using

    return intAffectedRowCount
End Function

Does this close off everything opened properly?


ORIGINAL QUESTION:

I am currently using the following code to update a row in a database table:

objSQLConnection = New SqlConnection(System.Configuration.ConfigurationManager.AppSettings("connString"))

objSQLCommand = New SqlCommand("update table1 set col1 = @col1 where id = @id", objSQLConnection)

objSQLCommand.Parameters.Add("@col1", SqlDbType.VarChar, 255).Value = strCol1Data
objSQLCommand.Parameters.Add("@id", SqlDbType.Int, 4).Value = intID

objSQLCommand.Connection.Open()
objSQLCommand.ExecuteNonQuery()
objSQLCommand.Connection.Close()

If I run that query in sql server, it returns a message saying “1 row affected”.

It’s probably possible to access the same message from asp.net, but I don’t know how to access it.

Even if I get a count, i.e. 1.

Anyone know how to get a count of the rows affected?

  • 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-23T17:05:40+00:00Added an answer on May 23, 2026 at 5:05 pm

    From the docs for SqlCommand.ExecuteNonQuery:

    Return Value

    Type: System.Int32
    The number of rows affected.

    So where you’re executing ExecuteNonQuery and currently ignoring the return value, just don’t ignore it 🙂

    (You should also use a Using statement to make sure that you don’t leak connections etc.)

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

Sidebar

Related Questions

Update: This does work, I was being stupid :( i have the following extension
If I try to implement this simple-as-possible example: Update Content with AJAXRefreshRequest it does
The Arcana Elite Suite for Intraweb hasn't been updated since March 2008. Does this
My ascx control inside a container update panel does a full page refresh when
I'm trying to display an update progress loading image whenever my update panel does
My code does not update the thread field. It is null. Anyone have any
It looks like Django does not update last_login field in auth_user model when a
I'm trying to write an after update trigger that does a batch update on
Update : Looks like the query does not throw any timeout. The connection is
Does Microsoft force an update down to all of its users of windows-update? Is

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.