[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 228
  • Last Modified:

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.
0
rmmarsh
Asked:
rmmarsh
1 Solution
 
UnifiedISCommented:
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

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now