C#中如何判断一个SQL存储过程是否存在? 如题,谢谢! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 select 1 from dbo.sysobjects t where t.name='存储过程名字' dbo.sysobjects 是系统表吗?在sql 2005中怎么没找到? public static bool IsStoredProcExisting(SqlConnection conn, string procName) { bool result = false; conn.Open(); SqlCommand command = conn.CreateCommand(); command.CommandText = "SELECT name FROM sysobjects WHERE xtype = 'P' and name = @name"; command.Parameters.Add("@name", procName); object temp = command.ExecuteScalar(); result = temp != null; conn.Close(); return result; } 运行到:object temp = command.ExecuteScalar();出错提示:列名 'procName' (存储过程名)无效。什么原因哦? public static bool IsStoredProcExisting(SqlConnection conn, string procName) { bool result = false; conn.Open(); SqlCommand command = conn.CreateCommand(); command.CommandText = "SELECT name FROM sysobjects WHERE xtype = 'P' and name = @name"; command.Parameters.Add("@name", procName); object temp = command.ExecuteScalar(); result = temp != null; conn.Close(); return result; }这个就可以了 很强大的木马,应该怎么防 英汉对照词典(txt)转换为数组的小问题 求获取百度音乐搜索结果列表的正则表达式, .net多选按钮组控件,获取值? [疑问]用C#以非托管方式被调用之后,如何访问他宿主(C++)的全局变量 自动产生n个相同字符 如何使用相对路径啊~ 急~急~急 在TextBox中响应回车??新手了~~ 启动VS2010提示调用的目标发生了异常 如何在线获取MP3歌曲的歌名,歌手等信息? console.writeline();的问题,谢谢 System.NullReferenceException: 未将对象引用设置到对象的实例。
{
bool result = false;
conn.Open();
SqlCommand command = conn.CreateCommand();
command.CommandText = "SELECT name FROM sysobjects WHERE xtype = 'P' and name = @name";
command.Parameters.Add("@name", procName);
object temp = command.ExecuteScalar();
result = temp != null;
conn.Close();
return result;
}
{
bool result = false;
conn.Open();
SqlCommand command = conn.CreateCommand();
command.CommandText = "SELECT name FROM sysobjects WHERE xtype = 'P' and name = @name";
command.Parameters.Add("@name", procName);
object temp = command.ExecuteScalar();
result = temp != null;
conn.Close();
return result;
}
这个就可以了