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 回答