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

  • Home
  • SEARCH
  • 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 1023297
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T11:35:42+00:00 2026-05-16T11:35:42+00:00

In my code neither of these queries appear to be running. The debug label

  • 0

In my code neither of these queries appear to be running. The debug label is printing as “end” so it is executing something inside that code block, just appears it doesn’t like the queries?

// Check input is all valid
if (Page.IsValid)
{
    debug.Text = "begin";

    using (SqlConnection cn = new SqlConnection(
       ConfigurationManager.ConnectionStrings["LocalSqlServer"].ToString()))
    {

        // Verify that username is unique
        using (SqlCommand cmd = new SqlCommand(
           "UPDATE tblSiteSettings SET isActive = 0", cn))
        {
            cn.Open();
            cn.Close();
        }

        using (SqlCommand cmd = new SqlCommand(
           "INSERT INTO tblSiteSettings (allowProductRatings, allowComments, " + 
           "siteName, settingDate, isActive) VALUES (@allowRatings, " +
           "@allowcomments, @siteName, getDate(), 1)", cn))
        {
            cmd.Parameters.Add("@allowRatings", SqlDbType.Bit).Value = 1;
            cmd.Parameters.Add("@allowcomments", SqlDbType.Bit).Value = 1;
            cmd.Parameters.Add("@siteName", SqlDbType.VarChar, 128).Value = "lol";
            cn.Open();
            cn.Close();
        }
        debug.Text = "end";
    }   
}

A few questions:

  1. Why are they not executing?
  2. In classic ASP for inserts, updates and deletes I would use con.Execute(query) as supposed to using a recordset, am I running my update statement correctly here?
  3. Is my design of the queries good, or should I be executing them in a different manner?
  • 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-16T11:35:43+00:00Added an answer on May 16, 2026 at 11:35 am

    The reason it’s not doing anything is because you’re not actually executing the queries. What you need to do is:

    // Verify that username is unique
    using (SqlCommand cmd = new SqlCommand("UPDATE tblSiteSettings SET isActive = 0", cn))
    {
        cn.Open();
        cmd.ExecuteNonQuery();
        cn.Close();
    }
    
    using (SqlCommand cmd = new SqlCommand("INSERT INTO tblSiteSettings (allowProductRatings, allowComments, siteName, settingDate, isActive) VALUES (@allowRatings, @allowcomments, @siteName, getDate(), 1)", cn))
    {
        cmd.Parameters.Add("@allowRatings", SqlDbType.Bit).Value = 1;
        cmd.Parameters.Add("@allowcomments", SqlDbType.Bit).Value = 1;
        cmd.Parameters.Add("@siteName", SqlDbType.VarChar, 128).Value = "lol";
        cn.Open();
        cmd.ExecuteNonQuery();
        cn.Close();
    }
    

    It’s the line cmd.ExecuteNoneQuery(); that you’re missing. There are various different Execute methods exposed by the SqlCommand class, the most commonly used are:

    • ExecuteNonQuery: Executes a query and returns no result from the query (it does return the rows affected as its return value however)
    • ExecuteScalar: Executes a query and returns the value in the first column of the first row
    • ExecuteReader: Executes a query and returns the data to a SqlDataReader
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Neither of these snippets of code work: int main() { struct mystruct { int
Code that is untestable really annoys me. The following things make oo-code untestable: global
(code examples are python) Lets assume we have a list of percentages that add
I bind a SQLDataSource to a GridView using GridView.DataBind() and these queries often take
I have a couple of queries for a web site that take a long
Code below does not run correctly and throws InvalidOperationExcepiton . public void Foo() {
Code: <html xmlns=http://www.w3.org/1999/xhtml> <head> <title>Unusual Array Lengths!</title> <script type=text/javascript> var arrayList = new Array();
Code I have: cell_val = CStr(Nz(fld.value, )) Dim iter As Long For iter =
Code and preview: <html> <head> <title>Testing some CSS</title> <style type=text/css> .dDay { font-size:205% }
Code below is not working as expected to detect if it is in design

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.