VS2008报告使用来自参数化存储过程的数据 [英] VS2008 report using data from a parametized Stored Procedure
问题描述
我想生成一个报告,显示单个员工使用来自SP的值以及从数据网格行传递的参数值的工资单。但是,生成的报告是空白的。我错过了什么以下是我的内容。
首先,我使用名为sqlselect的函数返回的值填充数据网格视图
Dim dbcall As 新 dbcalls
dtgPayslip_Old.DataSource = dbcall.sqlselect( empno AS Employee_Number, empname AS Employee_Name,date AS Date, payrollarchiveview)
其次我从datagrid视图中选择empno作为我传递给的参数值SP
私人 Sub dtgPayslip_Old_CellDoubleClick( ByVal sender As Object < /秒pan>, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs)句柄 dtgPayslip_Old.CellDoubleClick
Dim dbcall As 新 dbcalls
Dim empno As 字符串 = dtgPayslip_Old.Item( 0 ,dtgPayslip_Old.CurrentRow.Index).Value.ToString()
dbcall.CallparametizedSP( payrollarchivedataview, @ e,empno)
<
进行数据库调用的子程序
公共 Sub CallparametizedSP( ByVal procedureName As String ,< span class =code-keyword> ByVal 参数作为 字符串, ByVal 值作为 字符串)
conn.Open()
cmd.Parameters.AddWithValue(parameter,value)
cmd.Connection = conn
cmd.CommandType = CommandType.StoredProcedure
cmd.CommandText = procedureName
cmd.CommandTimeout = 6000
cmd.ExecuteScalar()
cmd.Dispose()
conn.Close()
在 l之后我希望员工的详细信息进入报告但我得到的只是列标题。我该如何解决这个问题。谢谢社区
MSDN:[ExecuteScalar]执行查询,返回查询返回的结果集中第一行的第一列。其他列或行将被忽略。
您可能必须使用ExecuteReader来获取数据而不是填充报告的数据源...但是您应该检查您的SP是否实际返回数据<!/ BLOCKQUOTE>
I want to generate a report showing payslips for a single employee using values from a SP with parameter values that have been passed from a datagrid row. However the report that is generated is blank. What am I missing. Below is what I have.
First I populate the datagrid view using values returned by a function called "sqlselect"
Dim dbcall As New dbcalls dtgPayslip_Old.DataSource = dbcall.sqlselect("empno AS Employee_Number,empname AS Employee_Name, date AS Date", "payrollarchiveview")
Secondly i select empno from datagrid view as the parameter value which I pass to the SP
Private Sub dtgPayslip_Old_CellDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dtgPayslip_Old.CellDoubleClick Dim dbcall As New dbcalls Dim empno As String = dtgPayslip_Old.Item(0, dtgPayslip_Old.CurrentRow.Index).Value.ToString() dbcall.CallparametizedSP("payrollarchivedataview", "@e", empno)
<
The sub that makes a db call
Public Sub CallparametizedSP(ByVal procedureName As String, ByVal parameter As String, ByVal value As String) conn.Open() cmd.Parameters.AddWithValue(parameter, value) cmd.Connection = conn cmd.CommandType = CommandType.StoredProcedure cmd.CommandText = procedureName cmd.CommandTimeout = 6000 cmd.ExecuteScalar() cmd.Dispose() conn.Close()
After all this I would expect details of the employee into the report But all I get are the column headings. How can I resolve this. Thank you community解决方案MSDN:[ExecuteScalar] Executes the query, and returns the first column of the first row in the result set returned by the query. Additional columns or rows are ignored.
You probably have to use ExecuteReader to get the data and than fill a data source for the report...However you should check that your SP actually returns data!
这篇关于VS2008报告使用来自参数化存储过程的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!