现在我真累了! 我有这个SP应该采用两个参数和返回五。我试图调用此SP和用于准备报告的返回值。我不知道我做错了什么。请帮忙。这是我的第一个应用程序,我是编程的初学者。任何好的帮助都会非常感激!在此先感谢。
USE [Cmanager]
GO
/****** Object: StoredProcedure [dbo].[MonthReport] Script Date: 14-Jan-15 11:01:07 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER Proc [dbo].[MonthReport]
@toReportDate as datetime = null,
@fromReportDate as datetime = null,
@totalOffering money = null output,
@totalVow money = null output,
@totalTithe money = null output,
@totalMisc money = null output,
@totalIncome money = null output
as
BEGIN
Select @totalIncome= Sum(Amount) from IncomeReport where IncDATE between @fromReportDate and @toReportDate
Select @totalOffering = Sum(OfferingAmount) from Offering where OfferingDate between @fromReportDate and @toReportDate
Select @totalTithe =Sum(TitheAmount) from Tithe where TitheDate between @fromReportDate and @toReportDate
select @totalVow = Sum(VowAmount) from Vows where VowDate between @fromReportDate and @toReportDate
Select @totalMisc =Sum(MiscAmount) from Miscellaneous where MiscDate between @fromReportDate and @toReportDate
SELECT @totalIncome as N'TotalIncome',
@totalOffering as N'TotalOffering',
@totalVow as N'TotalVow',
@totalTithe as N'TotalTithe',
@totalMisc as N'TotalMisc'
return
END
我正在使用它们在Visual Studio中调用SP
//try
//{
DataTable dt = new DataTable();
SqlConnection con = new SqlConnection(@"Data Source=EPRAISE-PC;Initial Catalog=Cmanager;Integrated Security=True");
con.Open();
SqlCommand cmd = new SqlCommand("MonthReport", con);
// Input Stored Procedure Parameters
//var pa = cmd.Parameters.Add(new SqlParameter("@fromReportDate", SqlDbType.Date));
//cmd.Parameters.AddWithValue("@fromReportDate", fromMonthDate.Text.Trim());
cmd.Parameters.Add(new SqlParameter("@toReportDate", SqlDbType.DateTime)).Value =
Convert.ToDateTime(toMonthDate.Text.Trim());
cmd.Parameters.Add(new SqlParameter("@fromReportDate", SqlDbType.DateTime)).Value =
Convert.ToDateTime(fromMonthDate.Text.Trim());
//pa.Value = fromMonthDate.Text;
//pa.Direction = ParameterDirection.Input;
//var p = cmd.Parameters.Add(new SqlParameter("@toReportDate", SqlDbType.Date));
//cmd.Parameters.AddWithValue("@toReportDate", toMonthDate.Text.Trim());
//p.Value = toMonthDate.Text;
//p.Direction = ParameterDirection.Input;
//Output Stored Procedure Parameters
using( DataSet ds = new DataSet())
{
ds.Clear();
SqlDataAdapter ada = new SqlDataAdapter(cmd);
ada.SelectCommand.CommandTimeout = 0;
ada.Fill(ds);
con.Close();
if (ds.Tables[0].Rows.Count == 0)
{
MessageBox.Show("No Record found within the period selected", "Response", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation);
return;
}
else
{
Cmanager.XtraReport1 report = new XtraReport1();
var tt = (from DataRow row in dt.Rows
select new monthlyRptClass
{
TotalIncome = Convert.ToDecimal(row["@totalIncome"]),
TotalVow = Convert.ToDecimal(row["@totalVow"]),
TotalOffering = Convert.ToDecimal(row["@totalOffering"]),
TotalTithe = Convert.ToDecimal(row["@totalTithe"]),
TotalMiscellaneous = Convert.ToDecimal(row["@totalMisc"]),
});
var binding = (BindingSource)report.DataSource;
binding.DataSource = tt; //wahala spot
report.ShowPreviewDialog();
con.Close();
}
}
var TotalIncome = cmd.Parameters.Add(new SqlParameter("@totalIncome", SqlDbType.Money));
TotalIncome.Direction = ParameterDirection.Output;
var TotalVow = cmd.Parameters.Add(new SqlParameter("@totalVow", SqlDbType.Money));
TotalVow.Direction = ParameterDirection.Output;
var TotalOffering = cmd.Parameters.Add(new SqlParameter("@totalOffering", SqlDbType.Money));
TotalOffering.Direction = ParameterDirection.Output;
var TotalTithe = cmd.Parameters.Add(new SqlParameter("@totalTithe", SqlDbType.Money));
TotalTithe.Direction = ParameterDirection.Output;
var TotalMiscellaneous = cmd.Parameters.Add(new SqlParameter("@totalMisc", SqlDbType.Money));
TotalMiscellaneous.Direction = ParameterDirection.Output;
cmd.ExecuteNonQuery();