473,322 Members | 1,755 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

File Upload Problem

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
Jan 3 '06 #1
2 1302
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

"Wayne Wengert" <wa***********@wengert.org> wrote in message
news:uy**************@TK2MSFTNGP14.phx.gbl...
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

Jan 3 '06 #2
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

"Vivek Thakur" <vi***@vivekthakur.com> wrote in message
news:eJ**************@TK2MSFTNGP14.phx.gbl...
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

"Wayne Wengert" <wa***********@wengert.org> wrote in message
news:uy**************@TK2MSFTNGP14.phx.gbl...
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


Jan 3 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: matt | last post by:
I have compiled some code, some written by me, some compiled from various sources online, and basically i've got a very simple flat file photo gallery. An upload form, to upload the photos and give...
3
by: Bijoy Naick | last post by:
I've written a simple file upload user control in VB .NET. It comprises of an InputFile HTML Server Control, an Upload button and a message label. User clicks on the Browse button of the...
6
by: tshad | last post by:
I have an upload file input as: <input id="MyFile" style="width:300px" type="File" runat="Server"> This works fine, but I find that if my page doesn't pass validation during postback, the page...
18
by: Jen | last post by:
I'm using Microsoft's own VB.NET FTP Example: http://support.microsoft.com/default.aspx?scid=kb;en-us;832679 I can get the program to create directories, change directories, etc., but I can't...
4
by: Matt Jensen | last post by:
Howdy I've got a rather strange issue occuring. I used forms based .NET authentication, although I'm also setting some session variables when people login. However, I've found when people use...
5
by: William LaMartin | last post by:
I have a VB ASP.Net application where the user can upload a file using the FileUpload server control. I also want a thumbnail to be created for this file. Unfortunately I can see no means to...
4
by: riteshjain82 | last post by:
Hi, Please go through this: I am having a file (default.asp) on which i am taking many details from a user before mailing it to someone. I have also provided the user with a facility of...
6
by: Vic Spainhower | last post by:
Hello, I am trying to do a FTP file upload which works fine on my localhost but on my ISP server it fails. I can't seem to find where I can go to find the specific cause of the failure. In both...
7
by: pbd22 | last post by:
hi. i am having probs understanding how to grab a file being uploaded from a remote client. i am using hidden input fields for upload such as: <input id="my_file_element" type="file"...
1
by: pbd22 | last post by:
hi. i have been posting this here and elsewhere a lot and can't seem to get resolution on this problem. i have been trying to upload files using a hidden iframe to a asp.net/vb.net form. the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.