0
我在使用存儲過程如何在數據庫中插入數據時遇到了問題。每次運行我的代碼時,都會出現此消息 「過程或函數'ScheduleofFeesInsert'需要參數'@SchoolYear',該參數未提供。」使用存儲過程在數據庫中插入datagridview數據vb.net
這裏是我的VB代碼:
Private Sub btnSet_Click(sender As Object, e As EventArgs) Handles btnSet.Click
Dim strConn As String = "Data Source=Jansen;Initial
Catalog=SLCBRegistrarDB;Integrated Security=True"
Dim sqlCon As SqlConnection = New SqlConnection(strConn)
Dim i As Integer = 0
CMD = New SqlCommand
CMD.Connection = sqlCon
CMD.CommandText = "ScheduleofFeesInsert"
CMD.CommandType = CommandType.StoredProcedure
'Save Current Fees
sqlCon.Open()
CMD.Parameters.AddWithValue("@AcademicYear", My.Settings.SchoolYear)
CMD.Parameters.AddWithValue("@Period", My.Settings.CurrentPeriod)
CMD.Parameters.Add(New SqlParameter("@FeeID", SqlDbType.Int))
CMD.Parameters.Add(New SqlParameter("@Amount", SqlDbType.Decimal))
For Each row As DataGridViewRow In dgvScheduleofFees.Rows
If Not row.IsNewRow Then
CMD.Parameters("@Amount").Value = row.Cells(0).Value
CMD.Parameters("@FeeID").Value = row.Cells(1).Value
CMD.ExecuteNonQuery()
End If
Next
sqlCon.Close()
End Sub
和SQLServer存儲過程:
USE [SLCBRegistrarDB]
GO/****** Object: StoredProcedure [dbo].[ScheduleofFeesInsert] Script
Date: 7/10/2017 4:00:34 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[ScheduleofFeesInsert]
@Period nvarchar(50),
@SchoolYear nvarchar(50),
@FeeID int,
@Amount decimal(18,0)
AS
Begin
Declare @PeriodID int
Declare @SYID int
Select @PeriodID=SemID FROM SemesterList where [email protected]
Select @SYID=[SY ID] FROM SchoolYear where [School Year][email protected]
INSERT INTO FEESSetup VALUES (@FeeID,@Amount,@PeriodID,@SYID)
END
我不知道我會錯過。我試圖修改我的代碼,但沒有任何反應。請幫忙。
( 「@AcademicYear」,My.Settings.SchoolYear),改( 「@SchoolYear」,My.Settings.SchoolYear) – Prathyush
哇!我沒有看到那個......哈哈,謝謝兄弟,你是一個很大的幫助。 – Diaval
oww..apologies兄弟,我只是一個初學者,我只是新的與stackoverflow。請教我如何將這個問題標記爲答案。謝啦。 :) – Diaval