I am building a website (digital repository for learning objects)with Microsoft visual studio 2005/ vb.net and sql2005
I used the following code which allows the user to create his own personal collection of learning objects
(the user enters the name of the personal collectionin atext box and clicks on create)
then the table of personal collection shold be changed to include the user inputs.
Protected Sub CreatePC_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles CreatePC.Click Dim myConnection As SqlConnection Dim myTransaction As SqlTransaction = Nothing Dim cmd As String = "INSERT INTO PersonalCollection(PCID,PCName,AccID) Values (@PCID,@PCName,@AccID)" Try myConnection = New SqlConnection(ConfigurationManager.ConnectionStrings("DBConnectionString1").ToString()) myConnection.Open() myTransaction = myConnection.BeginTransaction() Dim myCommand As SqlCommand = New SqlCommand(cmd, myConnection, myTransaction) myCommand.Parameters.AddWithValue("PCID", 4) myCommand.Parameters.AddWithValue("PCName", PCName.Text) myCommand.Parameters.AddWithValue("AccID", 53) myCommand.ExecuteNonQuery() Catch ex As Exception If (myTransaction.Equals(Nothing) = False) Then myTransaction.Rollback() End If myTransaction.Commit() Finally myConnection.Dispose() End Try End Sub
but unfortunatly an error appears for the line:
If (myTransaction.Equals(Nothing) = False) Then
the error:"NullReferenceException was unhandled by user code"
"Object reference not set to an instance of an object"
help please
