1

このコードは会計年度を自動的に更新します...

 Dim yearVal As Double
 If Date.Now.Month = 10 OrElse Date.Now.Month = 11 OrElse Date.Now.Month = 12 Then
     yearVal = Date.Now.Year
 Else
     yearVal = Date.Now.Year - 1
 End If

毎年これが次の年に変わると、このSQLストアドプロシージャを自動的に実行したい...

ALTER PROCEDURE dbo.NewBudget
    @year int,
    @int nvarchar(3)

AS
BEGIN
SET NOCOUNT ON;

    INSERT [NAOLI].[dbo].[BudgetReal]
    ([F_Year],[O_OrgCode],[O_OrgDesc],[S_SubObject],[S_SubDescrip],[B_BudgetAmt],[B_Initials],[B_CIPrefNo],[B_OrgBudgetAmt]) 
    SELECT @year as [F_Year],[O_OrgCode],[O_OrgDesc],[S_SubObject],[S_SubDescrip], 0.00 as [B_BudgetAmt],@int as [B_Initials],[B_CIPrefNo],[B_OrgBudgetAmt]
    FROM [NAOLI].[dbo].[BudgetReal]
END

行く

どうすればこれを実現できますか?

これでうまくいきました

Dim yearVal As Double
    If Date.Now.Month = 10 OrElse Date.Now.Month = 11 OrElse Date.Now.Month = 12 Then
        yearVal = Date.Now.Year
            If yearVal = Date.Now.Month = 10 OrElse Date.Now.Month = 11 OrElse Date.Now.Month = 12 Then
                dt = dal.ExecuteSelectStoredProc(dal.dbType.SqlServer, "NewBudget", "@year", DropDownList1.Text, "@int", )
            End If
    Else
        yearVal = Date.Now.Year - 1
    End If

みんなの助けに感謝します。

4

1 に答える 1

1

ADO.NETデータベースに接続するには、を使用する必要があります。RDBMS に基づく接続文字列が必要になります。IF次に、これをクラスに入れて、条件文ブロックで呼び出すことができます。

Dim sqlConnection1 As New SqlConnection("Your Connection String")
Dim cmd As New SqlCommand
Dim reader As SqlDataReader

cmd.CommandText = "dbo.NewBudget"
cmd.CommandType = CommandType.StoredProcedure
cmd.Parameters.Add("@year").Value = yearVal
cmd.Parameters.Add("@int").Value = intValue 'No idea why you have a Stored Procedure paramter called @int

cmd.Connection = sqlConnection1

sqlConnection1.Open()

reader = cmd.ExecuteNonQuery()
' Data is accessible through the DataReader object here.

sqlConnection1.Close() 

http://msdn.microsoft.com/en-us/library/d7125bke(v=vs.80).aspx#Y1200

http://www.connectionstrings.com

于 2012-05-24T14:57:47.463 に答える