static void Main(string[] args) { string 表名 = "water_emstime"; string sql = "exec GetTableSelect " + 表名; string ConString = "server=xxx.xxx.xx.xx;database=newFW;uid=sa;pwd=sa"; SqlDataAdapter da = new SqlDataAdapter(sql, ConString); DataSet ds = new DataSet(); da.Fill(ds); string ParmsList = ""; foreach (DataRow item in ds.Tables[0].Rows) { ParmsList += item[0].ToString() + "\n"; } string Select = ""; Select += ds.Tables[1].Rows[0][0].ToString()+"\n"; foreach (DataRow item in ds.Tables[2].Rows) { Select += item[0].ToString() + "\n"; } //根据表生成的查询存储过程 string procSelect = string.Format(@"create proc [dbo].[get_{0}] ( {1} ) as begin {2} end", 表名, ParmsList, Select);//表名 、参数列表 、查询语句 // create proc [dbo].[oper_water_alarm] //( // @Param_monitoring_mn varchar(32)=Null, // @Param_factor_id varchar(32)=Null, // @Param_datatime datetime=Null, // @Param_value numeric(9)=Null, // @Param_flag varchar(10)=Null, // @Param_action int //) //as //begin // if(@Param_action=0) // begin // insert into water_alarm(monitoring_mn, //factor_id, //datatime, //value, //flag) // values (@Param_monitoring_mn, //@Param_factor_id, //@Param_datatime, //@Param_value, //@Param_flag); // end // else if(@Param_action=1) // begin // delete water_alarm // where [email protected]_monitoring_mn // end // else // begin // Update water_alarm set [email protected]_monitoring_mn, // [email protected]_factor_id , // [email protected]_datatime , // [email protected]_value , // [email protected]_flag // where [email protected]_monitoring_mn // end //end }
时间: 2024-11-07 21:50:47