存储过程适合

时间:2017-04-18 06:04:34

标签: asp.net sql-server vb.net stored-procedures

如果使用sqlcommand语句

,如何在以下代码中调用存储过程
<WebMethod> _
Public Function GetPtPrt() As String
    Dim constr As String = ConfigurationManager.ConnectionStrings("ARTSQLConStrng").ConnectionString
    Using con As New SqlConnection(constr)
        Using cmd As New SqlCommand("SELECT TblRegjoin.PrtFilenum, TblReg.Fname + ' ' + TblReg.Sname + ' ' + TblReg.Lname, PrtStatus FROM TblReg INNER JOIN TblRegjoin ON TblReg.Filenum = TblRegjoin.PrtFilenum WHERE (TblRegjoin.PtFilenum = 15090248) ORDER BY TblRegjoin.PrtFilenum")
            cmd.Connection = con
            Dim ds As New DataSet()
            Using sda As New SqlDataAdapter(cmd)
                sda.Fill(ds, "PtPrt")
            End Using
            Return ds.GetXml()
        End Using
    End Using
End Function

1 个答案:

答案 0 :(得分:2)

试试这个:

<WebMethod> _
    Public Function GetPtPrt() As String
        Dim constr As String = ConfigurationManager.ConnectionStrings("ARTSQLConStrng").ConnectionString
        Using con As New SqlConnection(constr)
            Using cmd As New SqlCommand("ProcedureName", con)
                cmd.CommandType = CommandType.StoredProcedure
                cmd.Connection = con
                Dim ds As New DataSet()
                Using sda As New SqlDataAdapter(cmd)
                    sda.Fill(ds, "PtPrt")
                End Using
                Return ds.GetXml()
            End Using
        End Using
    End Function

希望它有所帮助。