gpt4 book ai didi

c# - 如何从 VB.net(或 C#)调用 sql server 函数?有存储过程之类的语法吗?

转载 作者:太空狗 更新时间:2023-10-29 20:53:46 25 4
gpt4 key购买 nike

Public Sub cleanTables(ByVal prOKDel As Short)
Dim sqlParams(1) As SqlParameter
Dim sqlProcName As String
sqlProcName = "db.dbo.sp_mySP"
sqlParams(1) = New SqlParameter("@OKDel", prOKDel)
Try
dbConn.SetCommandTimeOut(0)
dbConn.ExecuteNonQuery(CommandType.StoredProcedure, sqlProcName, sqlParams)
Catch ex As Exception

Finally

End Try
End Sub

有没有

 CommandType.StoredProcedure...CommandType.Function
sqlParams(1) = New SqlParameter("@OKDel", prOKDel)...

最后是数据表 dt = dbConn.Execute(CommandType.StoredProcedure, sqlProcName, sqlParams)

谢谢

最佳答案

抱歉,没有办法直接运行函数。使用 sql 文本命令调用它

Public Sub RunFunction(ByVal input As Short)
Using myConnection As New Data.SqlClient.SqlConnection
Using myCommand As New Data.SqlClient.SqlCommand("Select dbo.MyFunction(@MyParam)", myConnection)
myCommand.CommandType = CommandType.Text
myCommand.Parameters.Add(New Data.SqlClient.SqlParameter("@MyParam", input))
myCommand.CommandTimeout = 0
Try
myCommand.ExecuteNonQuery()
Catch ex As Exception

End Try
End Using

End Using
End Sub

或者在它周围包裹一个过程...

Create Procedure RunMyFunction(@MyParam as int)
Select * FROM dbo.MyFunction(@MyParam)
Go

关于c# - 如何从 VB.net(或 C#)调用 sql server 函数?有存储过程之类的语法吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1300052/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com