这是我的存储过程:
CREATE PROCEDURE [dbo].[GetDailyRecon]
@DT DATE,
@ReviewedBy VARCHAR(20) OUTPUT,
@ApprovedBy VARCHAR(20) OUTPUT
AS
BEGIN
SET NOCOUNT ON;
SELECT
'Account 23851 Balance' AS 'Description', AccountBalance AS 'Amount'
FROM
ReconRecords
WHERE RecordDate = @DT
UNION ALL
SELECT
'Total Outstanding' AS 'Description', Outstanding
FROM
ReconRecords
WHERE RecordDate = @DT
UNION ALL
SELECT
'Future Dated Outstanding' AS 'Description', FutureOutstanding
FROM
ReconRecords
WHERE RecordDate = @DT
UNION ALL
SELECT
'Pension Check Run Prior To Deposit' AS 'Description', -PensionRun
FROM
ReconRecords
WHERE RecordDate = @DT
UNION ALL
SELECT
'Flex Batch' AS 'Description', -FlexBatch
FROM
ReconRecords
WHERE RecordDate = @DT
UNION ALL
SELECT
'TRS' AS 'Description', TRS
FROM
ReconRecords
WHERE RecordDate = @DT
UNION ALL
SELECT
'Flex Pay Percentage Checks' AS 'Description', FlexPercentage
FROM
ReconRecords
WHERE RecordDate = @DT
UNION ALL
SELECT
Description, Amount
FROM
ManualRecords
WHERE
RecordDate = @DT
UNION ALL
SELECT
'Total' AS 'Description',
(SELECT AccountBalance +
Outstanding +
FutureOutstanding +
PensionRun +
FlexBatch +
TRS +
FlexPercentage
FROM ReconRecords WHERE RecordDate = @DT) +
(SELECT ISNULL(SUM(Amount),0) FROM ManualRecords WHERE RecordDate = @DT) AS 'Amount'
SELECT @ReviewedBy = ReviewedBy FROM ReconRecords WHERE RecordDate = @DT
SELECT @ApprovedBy = ApprovedBy FROM ReconRecords WHERE RecordDate = @DT
END
GO
这是我的c#代码
private void Form1_Load(object sender, EventArgs e)
{
string connStr = "Data Source=servername;Initial Catalog=CheckRecon;Integrated Security=True";
SqlConnection conn = new SqlConnection(connStr);
SqlCommand cmd = new SqlCommand("GetDailyRecon", conn);
cmd.CommandType = CommandType.StoredProcedure;
SqlParameter DT = cmd.Parameters.Add("@DT", SqlDbType.Date);
SqlParameter ReviewedBy = cmd.Parameters.Add("@ReviewedBy", SqlDbType.VarChar);
SqlParameter ApprovedBy = cmd.Parameters.Add("@ApprovedBy", SqlDbType.VarChar);
DT.Direction = ParameterDirection.Input;
ReviewedBy.Direction = ParameterDirection.Output;
ApprovedBy.Direction = ParameterDirection.Output;
DT.Value = new DateTime(2015, 7, 17);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
dataGridView1.DataSource = dt;
}
当我运行应用程序时,表单打开并且datagridview为空,不会抛出任何错误。我希望datagridview用过程中的select语句的结果填充,在表单上将有单独的文本框,用于显示reviewby和approvedby输出参数。提前感谢您提供的任何帮助。