對於學校我們必須製作3層應用。具有數據庫,Web服務和客戶端部分。 現在我有以下存儲過程,3層應用問題
ALTER PROCEDURE dbo.addMovie
(
@film_naam nvarchar(50),
@film_hoofdrol nvarchar(50)
)
AS
/* SET NOCOUNT ON */
INSERT INTO tbl_film
(film_naam, film_status, film_hoofdrol)
VALUES(@film_naam,0,@film_hoofdrol)
RETURN
當我執行此,它的偉大工程。但是當我在我的web服務中嘗試它時,出現以下錯誤。
System.NullReferenceException:未將對象引用設置爲對象的實例。 at Movie_rent.Movie_web.addMovie(String film_naam)Movie_rent.Movie_web.addMovie(String film_naam,String film_hoofdrol)in D:\ School \ Programmeren VB.net \ Periode 2 \ Movie_rent \ Movie_rent \ App_code \ Movie_rentDB.vb:line 105 ,字符串film_hoofdrol)在d:\學校\ Programmeren VB.net \ Periode 2 \ Movie_rent \ Movie_rent \ Movie_web.asmx.vb:行40
我的web服務的一部分
<WebMethod()> _
Public Function addMovie(ByVal film_naam As String, ByVal film_hoofdrol As String) As Boolean
Dim Movie_rent As New Movie_rentDB()
Return Movie_rent.addMovie(film_naam, film_hoofdrol)
End Function
而且我Movie_rentDB類
Public Class Movie_rentDB
Private strApplicationName As String = "Movie rent"
Private strConnection As String
Private conMovie As SqlConnection
Private adapMovie As New SqlDataAdapter
Private CommandMovie As SqlCommand
Private DataSetMovie As New DataSet
Private sqlTransaction As SqlTransaction
Private objLoggingService As Logging.Logging = New Logging.Logging("d:\\WebService.log")
Public ReadOnly Property ConnectionString() As String
Get
Try
Return ConfigurationManager.ConnectionStrings("Movie_rent").ConnectionString
Catch ex As Exception
objLoggingService.WriteLine(strApplicationName, ex.Message)
Throw (ex)
End Try
Return ""
End Get
End Property
Public Sub CreateConnection()
Try
conMovie = New SqlConnection(ConnectionString)
Catch ex As Exception
objLoggingService.WriteLine(strApplicationName, ex.Message)
Throw (ex)
End Try
End Sub
Private Sub Prepare_StoredProcedureCall(ByVal strStoredProcedure As String)
Try
CommandMovie = New SqlCommand(strStoredProcedure, conMovie)
CommandMovie.CommandType = CommandType.StoredProcedure
adapMovie = New SqlDataAdapter(CommandMovie)
DataSetMovie = New DataSet()
conMovie.Open()
sqlTransaction = conMovie.BeginTransaction
CommandMovie.Transaction = sqlTransaction
Catch ex As Exception
objLoggingService.WriteLine(strApplicationName, ex.Message)
Throw (ex)
End Try
End Sub
Private Sub Finish_StoredProcedureCall()
Try
If (conMovie.State = ConnectionState.Open) Then
conMovie.Close()
End If
Catch ex As Exception
objLoggingService.WriteLine(strApplicationName, ex.Message)
Throw (ex)
End Try
End Sub
Public Function getAllMovies() As DataSet
Try
Prepare_StoredProcedureCall("getAllMovies")
adapMovie.Fill(DataSetMovie, "tbl_film")
sqlTransaction.Commit()
Catch ex As Exception
If Not (sqlTransaction Is Nothing) Then
sqlTransaction.Rollback()
End If
DataSetMovie = Nothing
objLoggingService.WriteLine(strApplicationName, ex.Message)
Throw (ex)
End Try
Try
Finish_StoredProcedureCall()
Catch ex As Exception
DataSetMovie = Nothing
Throw (ex)
End Try
Return DataSetMovie
End Function
Public Function addMovie(ByVal film_naam As String, ByVal film_hoofdrol As String) As Boolean
Dim bStatus As Boolean = False
Try
Prepare_StoredProcedureCall("addMovie")
With CommandMovie.Parameters
.AddWithValue("film_naam", film_naam)
.AddWithValue("film_status", 0)
.AddWithValue("film_hoofdrol", film_hoofdrol)
End With
CommandMovie.ExecuteNonQuery()
sqlTransaction.Commit()
bStatus = True
Catch ex As Exception
sqlTransaction.Rollback()
objLoggingService.WriteLine(strApplicationName, ex.Message)
Throw (ex)
End Try
Finish_StoredProcedureCall()
Return bStatus
End Function
希望任何人都可以幫我:)
什麼是*** Logging.Logging ***? – Kiquenet 2017-10-31 15:12:37