Skip to content
David Kittell
David Kittell

Application & System: Development / Integration / Orchestration

  • Services
    • Application Development
    • Online Application Integration
  • Code
  • Online Tools
  • Tech Support
David Kittell

Application & System: Development / Integration / Orchestration

Run SQL Statement

Posted on August 1, 2013October 26, 2015 By David Kittell
protected string sRunSQLStmnt(string sSQL)
    {
        string sReturn = "";
        //Declare the connection object
        SqlConnection sqlConn = new SqlConnection(connString);
        int numberOfRecords = 0;
        try
        {
            //Make the connection
            sqlConn.Open();

            //Declare the Command
            SqlCommand sqlCommand = new SqlCommand(sSQL + " SELECT @@ROWCOUNT AS DELETED;", sqlConn);

            //Execute the query
            numberOfRecords = sqlCommand.ExecuteNonQuery();
        }
        catch (Exception ex)
        {
            // sDebug += ex;
        }
        finally
        {
            if (sqlConn.State == System.Data.ConnectionState.Open)
            {
                sqlConn.Close();
            }

            sReturn = numberOfRecords.ToString() + " Rows Affected";
        }

        return sReturn;
    }
Originally Posted on August 1, 2013
Last Updated on October 26, 2015
All information on this site is shared with the intention to help. Before any source code or program is ran on a production (non-development) system it is suggested you test it and fully understand what it is doing not just what it appears it is doing. I accept no responsibility for any damage you may do with this code.

Related

Code CSharp MSSQL

Post navigation

Previous post
Next post

Related Posts

Mac OSX – Update DNS Based On WiFi

Posted on June 8, 2016June 8, 2016

I often have to bounce between WiFi at the office and the public WiFi so I finally put this script together. You will need to get the BSSID of your WiFi connection to replicate this but here is the code, of course you need to run this with sudo privileges…

Read More

PowerShell – IPv4 Range

Posted on March 10, 2016March 10, 2016

This first function is helpful to provide a range of IPv4 addresses within a set range function New-IPRange ($start, $end) { # created by Dr. Tobias Weltner, MVP PowerShell $ip1 = ([System.Net.IPAddress]$start).GetAddressBytes() [Array]::Reverse($ip1) $ip1 = ([System.Net.IPAddress]($ip1 -join ‘.’)).Address $ip2 = ([System.Net.IPAddress]$end).GetAddressBytes() [Array]::Reverse($ip2) $ip2 = ([System.Net.IPAddress]($ip2 -join ‘.’)).Address for ($x=$ip1; $x…

Read More

Remove duplicates in a string array

Posted on September 1, 2015October 26, 2015

//error_reporting(E_ALL); //ini_set(‘display_errors’, 1); echo "<p>Original:<br/>".$_GET[’input’]."</p>"; $pieces = explode(",", $_GET[’input’]); $result = array_unique($pieces); echo "<p>Updated:<br/>"; foreach($result as $print) { echo "$print,"; } echo "</p>"; Originally Posted on September 1, 2015Last Updated on October 26, 2015 All information on this site is shared with the intention to help. Before any source code…

Read More

Code

Top Posts & Pages

  • PowerShell - Rename Pictures to Image Taken
  • Front Page
  • C# - Start/Stop/Restart Services
  • MacPorts / HomeBrew - Rip CD tracks from terminal
  • PowerShell - Show File Extensions

Recent Posts

  • Javascript – Digital Clock with Style
  • BASH – Web Ping Log
  • BASH – Picture / Video File Name Manipulation
  • Mac OSX Terminal – Create SSH Key
  • Bash – Rename Picture

Top Posts

  • PowerShell - Rename Pictures to Image Taken
  • C# - Start/Stop/Restart Services
  • MacPorts / HomeBrew - Rip CD tracks from terminal
  • PowerShell - Show File Extensions
  • SQLite - Auto-Increment / Auto Generate GUID
©2025 David Kittell | WordPress Theme by SuperbThemes