如何从VB.net(或C#)调用sqlserver函数?是否有一些像存储过程的语法?

前端之家收集整理的这篇文章主要介绍了如何从VB.net(或C#)调用sqlserver函数?是否有一些像存储过程的语法?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
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)...

最后是datatable dt = dbConn.Execute(CommandType.StoredProcedure,sqlParams)

谢谢

抱歉,没有办法直接运行功能.使用sql Text命令调用
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
原文链接:https://www.f2er.com/vb/255860.html

猜你在找的VB相关文章