存储过程如下:
create procedure selectTree
(
@where nvarchar(50)=''
)
as
begin
declare @sql nvarchar(100)
set @sql='select * from tree '
if @where<>''
set @sql=@sql+@where
execute(@sql)
end程序代码:
SqlCommand com = new SqlCommand("selectTree", con);
com.CommandType = CommandType.StoredProcedure;
com.Parameters.Add("@where","where id<>1");
con.Open();
com.ExecuteNonQuery();
con.Close();现在我要在程序中调用这个存储过程要得到查询的结果,怎么做呢?
程序代码越简单越好。谢谢了
create procedure selectTree
(
@where nvarchar(50)=''
)
as
begin
declare @sql nvarchar(100)
set @sql='select * from tree '
if @where<>''
set @sql=@sql+@where
execute(@sql)
end程序代码:
SqlCommand com = new SqlCommand("selectTree", con);
com.CommandType = CommandType.StoredProcedure;
com.Parameters.Add("@where","where id<>1");
con.Open();
com.ExecuteNonQuery();
con.Close();现在我要在程序中调用这个存储过程要得到查询的结果,怎么做呢?
程序代码越简单越好。谢谢了
using (SqlConnection conn = new SqlConnection("server=.;database=demo;uid=sa;pwd=1"))
{
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@where", "where id <>1");
SqlDataAdapter adp = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
conn.Open();
adp.Fill(ds);
}
/// 返回一个DataSet
/// </summary>
/// <param name="procName"></param>
/// <param name="pter"></param>
/// <returns></returns>
public static DataSet GetDataSet(string selectTree , params SqlParameter[] pter)
{
SqlDataAdapter da = new SqlDataAdapter(selectTree , 数据库连接);
da.SelectCommand.CommandType = CommandType.StoredProcedure;
da.SelectCommand.Parameters.AddRange(pter);
DataSet ds = new DataSet();
da.Fill(ds);
return ds;
} public static string GetJQMS(string user_dlr, string in_date)
{
SqlParameter[] pter = new SqlParameter[]
{
new SqlParameter("@user_dlr",user_dlr), //参数
new SqlParameter("@in_date",in_date),//参数 };
return DBHelp.GetScalars("sumGJqms", pter);
}