I am trying to upload a file and add its name, date of the upload, etc. to a
DB table. The relevant code is shown below. SqlDataSource2 is the data
source I am using and it has a valid (I think) INSERT command. The error I
get is "Object reference not set to an instance of an object." pointing to
the 1st line that references SqlDataSource2. What did I overlook?
================ code =====================
Protected Sub Button2_Click(ByVal sender As Object, ByVal e As
System.EventArgs)
Dim saveDir As String = "\uploadfiles\"
Dim appPath As String = Request.PhysicalApplicationPath
If (FileUpload1.HasFile) Then
Dim sfileName As String = FileUpload1.FileName
Dim savePath As String = appPath + saveDir + FileUpload1.FileName
FileUpload1.SaveAs(savePath)
SqlDataSource2.InsertParameters("dateinput").Defau ltValue =
CStr(DateTime.Today)
SqlDataSource2.InsertParameters("docname").Default Value = sfileName
SqlDataSource2.Insert()
Comment.Text = ""
RadioButtonList1.Text = ""
UploadStatusLabel.Text = "Your file was saved as " & sfileName
Else
UploadStatusLabel.Text = "You did not specify a file to upload."
End If
End Sub