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

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.
rmmarshAsked:
Who is Participating?
 
UnifiedISConnect With a Mentor Commented:
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



0
 
rmmarshAuthor Commented:
Thank you so much... that did it...
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.