以文本方式查看主题 - Foxtable(狐表) (http://foxtable.net/bbs/index.asp) -- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2) ---- SQL 存储过程执行不能获取表格内容 (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=173930) |
-- 作者:qq252476275 -- 发布时间:2021/12/23 7:46:00 -- SQL 存储过程执行不能获取表格内容 Dim e As RequestEventArgs = Args(0) Dim cmd As New SQLCommand Dim obj As new Jobject \' 返回值,前端根据此进行相应的处理 obj("code") = 0 obj("count") = 0 obj("Info") = "" \' 数据源 Dim strDataSource As String If e.Values.ContainsKey("dataSource") Then strDataSource = e.Values("dataSource") Else obj("code") = "401" obj("Info") = "尚未指定dataSource参数!" End If \' 调用的存储过程 Dim strProcedureName As String If e.Values.ContainsKey("proName") Then strProcedureName = e.Values("proName") Else obj("code") = "401" obj("Info") = "尚未指定proName参数!" End If \' Output.show("开始准备参数") cmd.StoredProcedure = True \'表示CommandText内容不是标准的SQL语句,而是存储过程名 \' 写入输入参数 Dim bHaveOutPut As Boolean = False \' 是否有输出参数 Dim bHaveReturn As Boolean = False \' 是否有返回值 If e.Values.ContainsKey("return") Then bHaveReturn = e.Values("return") End If Dim arrParm As JArray Dim arrParamName As new List(of String) If e.Values.ContainsKey("param") Then arrParm = JArray.parse(e.Values("param")) \' Output.show(e.Values("param")) Functions.Execute("showMsg2Form1",e.Values("param")) Dim parName As String = "" \' 存储过程的参数名称 Dim parValue As String = "" \' 存储过程的参数值 Dim parOutput As Boolean = False \' 此参数为返回参数为FALSE, 输出参数为TRUE Dim bHaveOut As Boolean = False Dim parSize As Integer = 0 \' 输出参数的字节大小 Dim bHaveSize As Boolean = False \'获取各参数的值 For Each jt As JToken In arrParm \' 数组遍历 \' 变量重新初始化 parName = "" parValue = "" parOutPut = False parSize = 0 bHaveOut = False bHaveSize = False For Each jp As JProperty In jt \' 集合遍历 \'Output.Show( jp.name.ToString ) \'Output.Show( jp.value.ToString) Select Case jp.name.ToString Case "name" : parName = jp.value.ToString arrParamName.Add(parName) Case "value" : parValue = jp.value.ToString Case "output" : parOutput = jp.value.ToString bHaveOut = True bHaveOutPut = True Case "size" : parSize = Val(jp.value.ToString) bHaveSize = True End Select Next output.show("11111") \'根据输入值,选择执行函数 If bHaveSize Then \' 输入/输出参数且有size cmd.Parameters.add( parName , parValue , parOutput , parSize ) Else If bHaveOut = True Then \' 不指定size cmd.Parameters.add( parName , parValue , parOutput ) Else \' 输入参数 cmd.Parameters.Add( parName , parValue) End If End If output.show("2222") Next \' Output.Show("读取参数") End If Dim dt As DataTable If obj("code") = "0" Then If bHaveReturn Then \' 如果执行存储过程后有表格返回 output.show("准备执行存储过程") dt = cmd.ExecuteReader output.show("完成执行存储过程") output.show("计数:") \' obj("count") = Val(dt.DataRows.Count) output.show( Val(dt.DataRows.Count) ) \'遍历记录 Dim arr As new JArray For i As Integer = 0 To dt.DataRows.Count - 1 Output.Show(i) arr.Add(new JObject) Dim dr As DataRow = dt.DataRows(i) For Each dc As DataCol In dt.DataCols If dc.IsNumeric Then arr(i)(dc.Caption) = val(dr(dc.Name)) Else arr(i)(dc.Caption) = dr(dc.Name).ToString() End If Next Next obj("data") = arr Else \' 如果无表格返回 cmd.ExecuteNonQuery obj("count") = 1 End If output.show("记录参数及返回值") If bHaveOutPut Then Dim arr1 As New Jarray arr1.Add(new JObject) For Each ex As String In arrParamName arr1(0)("paramName") = ex arr1(0)("value") = cmd.Parameters(ex) Next obj("data1") = arr1 End If End If 粉色处报错: 传入e.Path : procedure procedure [{"name":"@addDate","value":"2021-12-19"}] 11111 2222 准备执行存储过程 完成执行存储过程 计数: errlog: 2021-12-23 07:40:59.5029 事件/函数:自定义函数,sqlProcedure 调用的目标发生了异常。 在 System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor) 在 System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments) 在 System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) 在 Foxtable.UserFunctions.Execute(String Name, Object[] Args) 未将对象引用设置到对象的实例。 在 UserCode.A7v0NGshqQurSnDuO(Object[] Args) 存储过程执行语句: exec proWorkAddVSKQ \'2021-12-19\' |
-- 作者:qq252476275 -- 发布时间:2021/12/23 7:52:00 -- cmd.CommandText = strProcedureName \' 指定存储过程名 漏了这一句, 报以下错误: 传入e.Path : procedure procedure [{"name":"@addDate","value":"2021-12-19"}] 11111 2222 准备执行存储过程 errlog: 2021-12-23 07:48:39.6419 事件/函数: Microsoft Jet 数据库引擎找不到输入表或查询 \'proWorkAddVSKQ\'。 确定它是否存在,以及它的名称的拼写是否正确。 在 System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(OleDbHResult hr) 在 System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult) 在 System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult) 在 System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult) 在 System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method) 在 System.Data.OleDb.OleDbCommand.ExecuteReader(CommandBehavior behavior) 在 System.Data.OleDb.OleDbCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior behavior) 在 System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) 在 System.Data.Common.DbDataAdapter.Fill(DataTable[] dataTables, Int32 startRecord, Int32 maxRecords, IDbCommand command, CommandBehavior behavior) 在 System.Data.Common.DbDataAdapter.Fill(DataTable dataTable) 在 Foxtable.SQLCommand.ExecuteReader(Boolean Save) 完成执行存储过程 计数: errlog: 2021-12-23 07:48:39.7329 事件/函数:自定义函数,sqlProcedure 调用的目标发生了异常。 在 System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor) 在 System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments) 在 System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) 在 Foxtable.UserFunctions.Execute(String Name, Object[] Args) 未将对象引用设置到对象的实例。 在 UserCode.A7v0NGshqQurSnDuO(Object[] Args) |
-- 作者:qq252476275 -- 发布时间:2021/12/23 7:55:00 -- alter proc proWorkAddVSKQ @addDate datetime as begin
--declare @addDate datetime
--set @addDate = \'2021-12-19\'
sel ect a.部门名称 , a.加班日期, sum(a.部门人数) / count(a.工人姓名) as 注册人数 , count(a.工人姓名) as 加班人数
, sum( case when b.Name is null then 0 else 1 end ) as 出勤人数
from ( sel ect * from neightWorkAddMain where 加班日期 = @addDate and 可用 = 1 ) as a
left join ( sele ct * from SQLsvr08.zkteco_datav2.dbo.FZR_WaiXieGongWorkTotalTime as a
where a.dateTime = @addDate
) as b on b.Name = a.工人姓名 and b.dateTime = a.加班日期
group by a.部门名称 , a.加班日期 end |
-- 作者:qq252476275 -- 发布时间:2021/12/23 7:58:00 -- cmd.ConnectionName = strDataSource 少了这个 请教下,哪里可以删除自己的新贴?
|
-- 作者:有点酸 -- 发布时间:2021/12/23 8:08:00 -- 不能删除的,也么有必要删除的哦 |
-- 作者:qq252476275 -- 发布时间:2021/12/23 8:10:00 -- \'遍历记录 Dim arr As new JArray For i As Integer = 0 To dt.DataRows.Count - 1 Output.Show(i) arr.Add(new JObject) Dim dr As DataRow = dt.DataRows(i) For Each dc As DataCol In dt.DataCols output.show(dc.Name) output.show( dr(dc.Name).ToString() ) \' If dc.IsNumeric Then \' arr(i)(dc.Caption) = val(dr(dc.Name)) \' Else \' arr(i)(dc.Caption) = dr(dc.Name).ToString() \' End If Next Next obj("data") = arr 为什么dc.caption 不能使用,只能使用dc.Name?
|
-- 作者:有点蓝 -- 发布时间:2021/12/23 9:02:00 -- 没有给表格的列设置标题,肯定就不会有caption |