How to use a SQL statement to control a block of C# statements

Posted on 2007-10-08
Last Modified: 2010-04-15
Using the following statement:

            commandString = "IF NOT EXISTS(SELECT 1 FROM syscolumns WHERE name = 'SubCatID')"

Is there a way that I can use this partial statement to control C# statements that follow?  (kind of an IF followed by a block of C# statements).  I want to be able to alter a table to a new format if the table has not been altered before.  It's not a simple job, because I have to backup the old table data, delete the old table, create a new table and then restore some of the data.
Question by:rmmarsh
    LVL 18

    Accepted Solution

    Use a scalar reader with a count statement SELECT COUNT(*) FROM syscolumns WHERE name = 'SubCatID'
    and convert the result to boolean for your if statement

    if cbool(executescalar("select count...)) then
    sorry for the vb, I can't recall c# convert syntax right now


    Author Comment

    Thank you so much... that did it...

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Find Ransomware Secrets With All-Source Analysis

    Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

    This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
    We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now