aspx.vb execute mssql StoredProcedure



'aspx.vb

Sub DoStoredProcedure(ByVal ProName As String, ByVal ProArgs As String)
        Dim con As System.Data.SqlClient.SqlConnection = New System.Data.SqlClient.SqlConnection
        con.ConnectionString = System.Web.Configuration.WebConfigurationManager.ConnectionStrings("At").ConnectionString
        Dim cmd As New System.Data.SqlClient.SqlCommand("& ProName &", con)

        '如果使用 cmd.CommandType = CommandType.StoredProcedure 並一一給值
        'cmd.Parameters.Add("@DestPGFile", SqlDbType.VarChar).Value = DateString
        'cmd.Parameters.Add("@DestPGName", SqlDbType.VarChar).Value = Second(Now)
        'cmd.CommandType = CommandType.StoredProcedure

        '如果使用 cmd.CommandType = CommandType.Text 並使用字串給值
        cmd.CommandType = System.Data.CommandType.Text
        cmd.CommandText = "EXEC " & ProName & " " & ProArgs
        con.Open()
        cmd.ExecuteNonQuery()
        con.Close()
    End Sub

-------------------------------------------------------------------


'mssql server sp


SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Paul Huang>
-- Create date: <20110826>
-- Description: <asp.net execute mssql sp>
-- =============================================
CREATE PROCEDURE [dbo].[Insert_PageList](
@DestPGFile VARCHAR(30)
,@DestPGName VARCHAR(20)
)
as
INSERT INTO PageList (PGFile,PGName ) Values (@DestPGFile,@DestPGName)
GO

沒有留言:

張貼留言