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'