Stored procedure return into DataSet in C# .Net

前端 未结 3 746
情话喂你
情话喂你 2020-11-30 05:02

I want to return virtual table from stored procedure and I want to use it in dataset in c# .net. My procedure is a little complex and can\'t find how to return a table and s

3条回答
  •  伪装坚强ぢ
    2020-11-30 05:44

    Try this

        DataSet ds = new DataSet("TimeRanges");
        using(SqlConnection conn = new SqlConnection("ConnectionString"))
        {               
                SqlCommand sqlComm = new SqlCommand("Procedure1", conn);               
                sqlComm.Parameters.AddWithValue("@Start", StartTime);
                sqlComm.Parameters.AddWithValue("@Finish", FinishTime);
                sqlComm.Parameters.AddWithValue("@TimeRange", TimeRange);
    
                sqlComm.CommandType = CommandType.StoredProcedure;
    
                SqlDataAdapter da = new SqlDataAdapter();
                da.SelectCommand = sqlComm;
    
                da.Fill(ds);
         }
    

提交回复
热议问题