اخواني الكرام
السلام عليكــم ورحمـة الله وبركاتــه ،،
عندي كود للحذف اعتمادا على StoredProcedure لا يعمل معي
الـ StoredProcedure هو التالي
ALTER PROCEDURE [dbo].[sp_MainAccount_Delete] ( @cl int output ) AS IF NOT EXISTS(SELECT * FROM [DT_Brnc] WHERE cl=@cl) BEGIN delete from [DT_Main] WHERE cl = @cl end select count(cl) from DT_Main where cl=@cl return
والفنشن الذي يقوم بالعمليه هو التالي
Public Function sp_MainAccount_Delete(ByRef cl As Integer) As Integer
Dim sqlcmdstr As String = "sp_MainAccount_Delete"
Dim sqlcmd As New SqlCommand(sqlcmdstr, SqlConnection)
Dim par As New SqlParameter
sqlcmd.CommandType = CommandType.StoredProcedure
par.ParameterName = "@cl"
par.Direction = ParameterDirection.Output
par.SqlDbType = SqlDbType.Int
sqlcmd.Parameters.Add(par)
Try
SqlConnection.Open()
Catch ex As Exception
MsgBox(ex.Message)
End
End Try
sqlcmd.ExecuteNonQuery()
Return sqlcmd.Parameters("@cl").Value
SqlConnection.Close()
End Functionكما استدعيت الفنشن بـ
Dim db As DBOperations = New DBOperations() Dim ID As Integer = CInt(Txt_ID.Text) Dim val As Integer = db.sp_MainAccount_Delete(ID)
يرجع لي خطا وهو التالي
Conversion from type 'DBNull' to type 'Integer' is not valid.
والفكره هي ان اتحقق هل تم الحذف ام لا وذلك اعتمادا على القيمة المرجعة
هل من حل لهذه المشكله
