Hi,
I am new to ASP.NET and i have been thrown into the deep end on a project, the person who created this code is no longer available. The website allows an Admin to login and edit, update or delete information in an SQL database referring to PDFs located on the server. the issue comes when trying to delete a record from the database.
This is the error i get:
Server Error in '/' Application.
--------------------------------------------------------------------------------
Procedure or Function 'Delete_Publication' expects parameter '@UID', which was not supplied.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.SqlClient.SqlException: Procedure or Function 'Delete_Publication' expects parameter '@UID', which was not supplied.
Source Error:
Line 92:
Line 93: myConnection.Open()
Line 94: myCommand.ExecuteNonQuery()
Line 95: myConnection.Close()
Line 96:
This is the code that is causing grief:
Imports System.IO
Imports System.Data
Imports System.Data.SqlClient
Imports System.Collections.Generic
Partial Class Delete_Exist_Publication
Inherits System.Web.UI.Page
Dim a, b, c, d As String
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
a = Request.QueryString("Title")
b = Request.QueryString("RefNo")
c = Request.QueryString("Rowguid")
Delete_Publication(b, c)
Delete_File()
Response.Write("<script>window.opener.location.href = window.opener.location.href;</script>")
Response.Write("<script>window.close();</script>")
'If Not Me.IsPostBack Then
' If Session("UserID") = "" Or Session("Active") = "False" Then
' Response.Redirect("Login.aspx")
' ElseIf Session("UserID") <> "" And Session("Active") = "True" Then
' 'Me.lblLoginId.Text = "You are logged in as: " + Session("UserID")
' 'Me.lblWorkType.Text = "Your Work Type is " + Session("WorkType")
' Approve_EventCalendar(b, c)
' Response.Write("<script>window.opener.location.href = window.opener.location.href;</script>")
' Response.Write("<script>window.close();</script>")
' End If
'Else
' If Session("UserID") = "" Or Session("Active") = "False" Then
' Response.Redirect("Login.aspx?Name=true")
' ElseIf Session("UserID") <> "" Then
' 'PopulateDetails(Session("UserID"))
' 'Me.lblLoginId.Text = "You are logged in as: " + Session("UserID")
' 'me.lblWorkType.Text = "Your Work Type is " + Session("WorkType")
' 'populate_Worktype()
' ' populate_SubType()
' 'populate_JobDetail(c)
' End If
'End If
End Sub
Private Sub ExpirePageCache()
Response.Cache.SetCacheability(HttpCacheability.NoCache)
Response.Cache.SetExpires(DateTime.Now - New TimeSpan(1, 0, 0))
Response.Cache.SetLastModified(DateTime.Now)
Response.Cache.SetAllowResponseInBrowserHistory(False)
End Sub
Private Sub Delete_Publication(ByVal RefNO As String, ByVal Rowguid As String)
Dim myConnection As SqlConnection = New SqlConnection(ConfigurationManager.AppSettings("ConnectionString"))
Dim myCommand As SqlCommand = New SqlCommand("Delete_Publication", myConnection)
' Mark the Command as a SPROC
myCommand.CommandType = CommandType.StoredProcedure
' Add Parameters to SPROC
'Session("UserID") = "Admin"
'@UID varchar(20)
Dim parameterUID As SqlParameter = New SqlParameter("@UID", SqlDbType.VarChar, 20)
parameterUID.Value = Session("UserID")
myCommand.Parameters.Add(parameterUID)
'@RefNo varchar(20)
Dim parameterRefNO As SqlParameter = New SqlParameter("@RefNo", SqlDbType.VarChar, 20)
parameterRefNO.Value = RefNO
myCommand.Parameters.Add(parameterRefNO)
'@Rowguid varchar(30)
Dim parameterRowguid As SqlParameter = New SqlParameter("@Rowguid", SqlDbType.VarChar, 40)
parameterRowguid.Value = Rowguid
myCommand.Parameters.Add(parameterRowguid)
myConnection.Open()
myCommand.ExecuteNonQuery()
myConnection.Close()
End Sub
Private Sub Delete_File()
Try
Dim TheFile As FileInfo = New FileInfo(MapPath(".") & "\pdf\" & b + ".pdf")
If TheFile.Exists Then
File.Delete(MapPath(".") & "\pdf\" & b + ".pdf")
'Me.lblFileInfo.Text = "You have successfully deleted the " + a + ".pdf file"
'Me.lblStatus.Visible = False
Else
Throw New FileNotFoundException()
End If
Catch ex As FileNotFoundException
lblStatus.Text += ex.Message
Catch ex As Exception
lblStatus.Text += ex.Message
End Try
End Sub
End Class
Any help would be great.
Thanks
Aaron