First ASP.NET application not going so well....

windows

Guest
Hey guys I am writing my first ASP.NET application and having some trouble

The purpose of this app is to upload a file to server (this part works) and then to also write the path and a description of the file to a database so I can pull that info out later. (this is the part that is broke)

Here is the source code

<%@ Page Language="VB" %>
<%@ import Namespace="System.Data.OleDb" %>
<script runat="server">

Sub Page_Load(Sender as Object, e as EventArgs)



Dim MyPath, MyName as String
'Display the names in C:\ that represent directories.

MyPath = "D:\hubbardtexas.net\docs" 'Set the Path
MyName = Dir(MyPath, vbDirectory) 'Retrieve the first entry.

if MyName="" 'The folder is not there & to be created

MkDir("D:\hubbardtexas.net\docs\") 'Folder created
span2.InnerHtml="A Folder (D:\hubbardtexas.net\docs) is created at the Page_Load"

end if

End sub



Sub Upload_Click(Sender as Object, e as Eventargs)

dim namevar = name.text

'Display properties of the uploaded file

FileName.InnerHTML = MyFile.PostedFile.Filename
FileContent.InnerHTML = MyFile.PostedFile.ContentType
FileSize.InnerHtml = MyFile.PostedFile.ContentLength
UploadDetails.visible = True


'Let us recover only the file name from its fully qualified path at client

Dim strFileName as string
strFileName = MyFile.PostedFile.FileName
Dim c as string = System.IO.Path.GetFileName(strFileName) ' only the attached file name not its path

'Let us Save uploaded file to server at D:\hubbardtexas.net\docs\

Try

MyFile.PostedFile.SaveAs("D:\hubbardtexas.net\docs\" + c)
Span1.InnerHtml = "Your File Uploaded Sucessfully at server as : D:\hubbardtexas.net\docs\"

catch Exp as exception
span1.InnerHtml = "An Error occured. Please check the attached file"
UploadDetails.visible = false
span2.visible=false

End Try

'<!-------------------------------ADD INFO TO DATABASE------------------------------>


Dim varpath = c
Dim varname = name.text

Dim nameAdd As OleDbConnection
Dim strInsert As String
Dim cmdInsert As OleDbCommand

nameAdd = New OleDbConnection( "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=D:\hubbardtexas.net\db\publicnotice.mdb" )
strInsert = "Insert Into publicnotice ( name, path ) Values ( varname, varpath )"
cmdInsert = New OleDbCommand( strInsert, nameAdd )
nameAdd.Open()
cmdInsert.ExecutenonQuery()
nameAdd.Close()



'<!-------------------------------END ADD INFO TO DATABASE------------------------------>

End Sub

</script>
<html>
<head>
</head>
<body>
<font face="Helvetica" color="darkgreen" size="5"><b>Uploading In ASP.Net - A Rich
Uploading ! </b></font>
<hr color="black" size="2" />
<p>
</p>
<form method="post" enctype="multipart/form-data" runat="Server">
Choose Your File To Upload :
<br />
<input id="MyFile" type="file" size="40" runat="Server" />
<br />
<asp:TextBox id="name" runat="server"></asp:TextBox>
<br />
<input type="submit" value="Upload" runat="Server" onserverclick="Upload_Click" />
<br />
<p>
</p>
<div id="UploadDetails" runat="Server" visible="False">File Name: <span id="FileName" runat="Server">
<br />
File Content: <span id="FileContent" runat="Server">
<br />
File Size: <span id="FileSize" runat="Server">bytes
<br />
</span></span></span>
</div>
<span id="Span1" style="COLOR: red" runat="Server"><span id="Span2" style="COLOR: red" runat="Server"></span></span>
</form>
<hr color="black" size="2" />
</body>
</html>


Here is the page in action

<!-- m --><a class="postlink" href="http://www.hubbardtexas.net/publicnoticeupload.aspx">http://www.hubbardtexas.net/publicnoticeupload.aspx</a><!-- m -->

Any help would be greatly appreciated.Hi,

I just tried your site and the crashing point happens when you are writing information to Access. Let me make sure we all understand your problem here: are you having trouble writing data into your sql table?

your thread covered a lot of stuff and it is hard to pin point what exactly is your problem, if you are having trouble writing stuff to your table, you need to make sure 1) you have the correct sql statement, 2)you have the correct connection string 3)you called the correct libraries to get the job done.

If you having trouble else where, please explain in detail.sorry to leave such sketchy info. yes...the problem i am having is getting these values to write to an access database.

The error that I am getting is No value given for one or more required paremeters. I believe what is happening is that the values are not getting passed into my variables i use to upload them.hi, just like to verify with you that:

1) take off the sql portion of your code, are you able to create file at the directory which you've planned? I ask is because by default, asp.net write its file to c:\winnt\ folder, and you need to use "Server.map("c:\your path");" to make sure the file is locate at the correct dirtory.

there's 3 major steps is happening at your code, retreieve file from user , write file to to server, and finally write data to sql.

I suggest break'em down 1 by 1 first, and pin point the problem from there, because it you are able to write file to your server, you -must- know the path in your code, therefore there's no way you can't write to your sql table.

break ur code down into module, and start from there, maybe we can locate the root causing problem

hope this helps a little...here...

strInsert = "Insert Into publicnotice ( name, path ) Values ( varname, varpath )"

change to,

strInsert = "Insert Into publicnotice ( name, path ) Values ( '" & varname & "', '" & varpath & "')"

and try again.
 
Back
Top