File Upload Problem

W

Wayne Wengert

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").DefaultValue =
CStr(DateTime.Today)

SqlDataSource2.InsertParameters("docname").DefaultValue = 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
 
V

Vivek Thakur

Wayne

U need to initialize the SqlDataSource2 object first by using the "new"
keyword and also set its various paramters like conneciton string, provider
etc.

Till then the object is null

-Vivek
 
W

Wayne Wengert

Vivek;

This is a fairly large solution (25 forms) and it depends on a SQL
Express2005 DB as well so it is not practical to send to anyone to look at.
As I mentiond in the off-line reply, I have a second SqlDataSource1 control
and executing SqlDataSource1.Update works fine?

Wayne
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top