SQL技巧(sp_procedure_params_rowset,SQL中设置数据值为null)

SQL技巧(sp_procedure_params_rowset,SQL中设置数据值为null) 1.在SQL Server数据库中要把某个字段改null? 语句:set xxxx=null; 快捷键:ctrl + 0; 2.得到任意一个存储过程的参数列表 方法1: select c.name from syscolumns c,sysobjects o where o.id=c.id and o.xtype='P' and o.name='your proc name' 方法2: exec sp_procedure_params_rowset @procedure_name = 'storeproc name' 例如: 1)、 select c.name,c.colorder from syscolumns c,sysobjects o where o.id=c.id and o.xtype='P' and o.name='proc_EMS_SearchEquipment' 得到 @type 1 @model 2 @location 3 @description 4 2)、sp_procedure_params_rowset @procedure_name='proc_EMS_SearchEquipment' DBName dbo proc_EMS_SearchEquipment;1 @RETURN_VALUE 0 4 0 NULL 0 3 NULL NULL 10 NULL NULL int int DBName dbo proc_EMS_SearchEquipment;1 @type 1 1 0 NULL 1 3 NULL NULL 10 NULL NULL int int DBName dbo proc_EMS_SearchEquipment;1 @model 2 1 0 NULL 1 129 50 50 NULL NULL NULL varchar varchar DBName dbo proc_EMS_SearchEquipment;1 @location 3 1 0 NULL 1 129 50 50 NULL NULL NULL varchar varchar DBName dbo proc_EMS_SearchEquipment;1 @description 4 1 0 NULL 1 129 100 100 NULL NULL NULL varchar varchar 3.怎样使用该函数 //执行存储过程 public DataSet ExecuteDataSet(string storedProcedure, params object[] param) { SqlCommand selectCommand = this.GenerateCommand(storedProcedure, param); selectCommand.CommandTimeout = 300; DataSet dataSet = null; SqlDataAdapter adapter = new SqlDataAdapter(selectCommand); try { dataSet = new DataSet(); adapter.Fill(dataSet); } catch (Exception exception) { throw exception; } finally { if (!this.UnderTran) { this.Connect.Close(); } } return dataSet; } //将传入的object[]值赋给对应存储过程参数 private SqlCommand GenerateCommand(string cmdstr, params object[] val) { SqlCommand command = new SqlCommand(cmdstr, this.Connect); command.CommandType = CommandType.StoredProcedure; if (!this.UnderTran && (this.Connect.State != ConnectionState.Open)) { this.Connect.Open(); } else { command.Transaction = this.Tran; } if ((val != null) && (val.Length > 0)) { SqlCommand selectCommand = new SqlCommand("sp_procedure_params_rowset", this.Connect); if (this.UnderTran) { selectCommand.Transaction = this.Tran; } selectCommand.CommandType = CommandType.StoredProcedure; selectCommand.Parameters.Add("@procedure_name", cmdstr); DataSet dataSet = new DataSet(); new SqlDataAdapter(selectCommand).Fill(dataSet); DataTable table = dataSet.Tables[0]; table.Rows.RemoveAt(0); for (int i = 0; i < val.Length; i++) { if (val[i] != null) { command.Parameters.Add(table.Rows[i]["PARAMETER_NAME"].ToString(), val[i]); } } } return command; } //调用函数 public DataTable SearchEquipment(int type,string model,string location,string description)//OSR.Entity.EMSData { object[] obj = new object[4]; obj[0] = type; obj[1] = model; obj[2] = location; obj[3] = description; return visitor.ExecuteDataSet("proc_EMS_SearchEquipment", obj).Tables[0]; }
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值