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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T23:31:47+00:00 2026-05-20T23:31:47+00:00

This has been stumping me for a few days now. I have a stored

  • 0

This has been stumping me for a few days now.

I have a stored procedure on a MS SQL 2008 server. I can connect through management studio and as the user I am using in my code and execute the stored procedure and it works how I expect it to. The problem comes in when I try to use it in my code. Here is my code:

 Dim strConn1 As String = "Data Source=server;Initial Catalog=db;User ID=user;Password=pass"
 Dim objconn1 As New SqlConnection(strConn1)
 Dim objCommand1 As New SqlCommand("storedProcedure", objconn1)
 objCommand1.CommandType = Data.CommandType.StoredProcedure
 objCommand1.Parameters.AddWithValue("@strEncounter", Encounter)
 objCommand1.Parameters.AddWithValue("@NetworkName", Employee)

 objconn1.Open()
 Dim test = objCommand1.ExecuteNonQuery()
 objconn1.Close()

When I run this it does nothing. There is no exception, no error, and the variable test which stores the number of rows affected from the method ExecuteNonQuery is 1. When I check the database to see the row it should have inserted there is nothing.

The other really strange thing is that I have the same code in an ASP.NET website and it works fine. I have copied it and pasted it exactly the same into this application which is a forms application and it will not work. Thanks.

  • 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-20T23:31:48+00:00Added an answer on May 20, 2026 at 11:31 pm

    Well, since you are using ExecuteNonQuery, “nothing” should happen in the application. ExecuteNonQuery says that an action is going to be performed on the SQL Server, and do not expect a returned result set.

    Now, if you are expecting a result set, you have to use a DataAdapter and .Fill() a DataTable object with the results:

    Dim dt As New DataTable
    Dim da As New SqlClient.SqlDataAdapter(objCommand1)
    da.Fill(dt)
    

    You’d only want to use ExecuteNonQuery when you are inserting, updating, or deleting rows. When you want to read data to the client app, you have to store it somewhere. As a side note, this is an argument against copy-n-paste coding 😉 Also, it’s arguably out of fashion to use bastardized Hungarian Notation (i.e. the “obj” prefix to your variables). It much more readable like this:

    Dim connString As String = "Data Source=server;Initial Catalog=db;User ID=user;Password=pass"
    Dim cn As New SqlConnection(connString)
    Dim cmd As New SqlCommand("storedProcedure", cn)
    
    cmd.CommandType = Data.CommandType.StoredProcedure
    cmd.Parameters.AddWithValue("@strEncounter", Encounter)
    cmd.Parameters.AddWithValue("@NetworkName", Employee)
    
    cn.Open()
    
    Dim dt As New DataTable
    Dim da As New SqlClient.SqlDataAdapter(cmd)
    da.Fill(dt)
    
    cn.Close()
    

    Everything prefixed with “obj” makes it harder for the eye to pick out the variables.

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

Sidebar

Related Questions

This has been driving me crazy for the past few minutes I have a
This has been bugging me for more than two days now, so i thought
This has been stumping me for a bit. I have a Class written in
This has been driving me crazy for 2 days. I have been trying to
This has been grinding my gears for at least a week now. I have
This has been driving me mad for a few days... Create a new Window-based
This has been stumping me for days... In my app i am using AVCapture
This has been driving me nuts for the last 2 days. I have 3
This has been bothering me for a long time now: Lets say i have
This has been bugging me for the last few hours now. I am using

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.