【发布时间】:2016-05-23 03:15:18
【问题描述】:
我正在尝试将此 SQL 示例命令转换为 C#SqlCommand:
if not exists (select column_name
from INFORMATION_SCHEMA.columns
where table_name = 'TotalHeals'
and column_name = '"+Healee+"')
alter table TotalHeals add +Healee+ int
我目前拥有的东西
// TO DO check to see if column exists instead of throwing error
cmd2 = new SqlCommand("ALTER TABLE TotalHeals ADD " + Healee + " INT",openCon);
cmd2.ExecuteNonQuery();
我完全不知道如何编写 if not exists 语句。有什么帮助吗?
【问题讨论】:
-
我动态添加列,不想在列已经存在时捕获异常
标签: c# sql-server sqlcommand