Hi
Could someone please check this code. It works fine other than its adding the new registration twice and also if a user doesnt supply a file to upload it comes up with an error along the lines that i was looking for the insert fields in the code
Thanks in advance
Could someone please check this code. It works fine other than its adding the new registration twice and also if a user doesnt supply a file to upload it comes up with an error along the lines that i was looking for the insert fields in the code
Thanks in advance
Code:
<script runat="server">
Sub doUploadCV
Dim strFileExtension As String
Dim strFileType As String
Dim intFileLen As Integer
Dim objStream As Stream
Dim conUploadCV As SqlConnection
Dim strInsert As String
Dim cmdInsert As SqlCommand
If Not IsNothing(UploadedFile.PostedFile ) Then
'Determine File Type
strFileExtension = RIGHT( UploadedFile.PostedFile.FileName, 4 )
SELECT Case strFileExtension.ToLower
CASE ".doc"
strFileType = "doc"
CASE ".pdf"
strFileType = "pdf"
End Select
'Grab the contents of uploaded file
intFileLen = UploadedFile.PostedFile.ContentLength
Dim arrFile( intFileLen ) As Byte
objStream = UploadedFile.PostedFile.InputStream
objStream.Read( arrFile, 0, intFileLen )
'Add uploaded file to database
conUploadCV = New SqlConnection("Server=xxx;UID=xxx;PWD=xxx;database=xxx" )
strInsert = "Insert dbo.CV (Title, AssociateRef, DocumentType, DocumentData ) Values (@Title, @AssociateRef, @filetype, @DocumentData )"
cmdInsert = New SqlCommand( strInsert, conUploadCV )
cmdInsert.Parameters.Add("@Title", Forename.text )
cmdInsert.Parameters.Add("@AssociateRef", AssociateRef)
cmdInsert.Parameters.Add("@fileType", strFileType )
cmdInsert.Parameters.Add("@DocumentData", arrFile )
conUploadCV.Open()
cmdInsert.ExecuteNonQuery()
conUploadCV.Close()
End If
End Sub
Sub Page_Load
btnSubmit.enabled = false
End Sub
Private Sub RegisterButtonEnabled (sender As Object, e As System.EventArgs)
If TermsBox.Checked = True Then
btnSubmit.enabled = True
Else
btnSubmit.enabled = false
End If
End Sub
Sub btnReset_Click(s As Object, e As EventArgs)
Title.SelectedItem.Text = ""
Forename.Text = ""
Surname.Text = ""
AddressLine1.Text = ""
AddressLine2.Text = ""
AddressLine3.Text = ""
AddressLine4.Text = ""
County.SelectedItem.Text = ""
Postcode.Text = ""
Region.SelectedItem.Text = ""
Company.Text = ""
Email_Address.Text = ""
HomePhone.Text = ""
BusinessPhone.Text = ""
MobilePhone.Text = ""
End Sub
Dim Password As String = Membership.GeneratePassword(7, 1)
Dim conn As SqlConnection
Dim cmd As SqlCommand
Dim strconnection, strsqlinsert As String
Dim AssociateRef As String
Private Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
strconnection = "Server=xxx;UID=sa;PWD=xxxx;database=xxx"
strsqlinsert = "Insert into dbo.Associates ( "
strsqlinsert + = "Title, Forename, Surname, AddressLine1, AddressLine2, AddressLine3, AddressLine4, County, Postcode, Region, Company, Email, HomePhone, BusinessPhone, MobilePhone, Password"
strsqlinsert + = ")"
strsqlinsert + = " values ("
strsqlinsert + = "@Title, @Forename, @Surname, @AddressLine1, @AddressLine2, @AddressLine3, @AddressLine4, @County, @Postcode, @Region, @Company, @EmailAddress, @HomePhone, @BusinessPhone, @MobilePhone, @Password"
strsqlinsert + = ")"
strsqlinsert + = "; SELECT SCOPE_IDENTITY() ; "
conn = New SqlConnection(strconnection)
cmd = New SqlCommand(strsqlinsert, conn)
cmd.Parameters.Add( "@Title", Title.SelectedItem.Text)
cmd.Parameters.Add( "@Forename", Forename.Text)
cmd.Parameters.Add( "@Surname", Surname.Text)
cmd.Parameters.Add( "@AddressLine1", AddressLine1.Text)
cmd.Parameters.Add( "@AddressLine2", AddressLine2.Text)
cmd.Parameters.Add( "@AddressLine3", AddressLine3.Text)
cmd.Parameters.Add( "@AddressLine4", AddressLine4.Text)
cmd.Parameters.Add( "@County", County.SelectedItem.Text)
cmd.Parameters.Add( "@Postcode", Postcode.Text.toUpper())
cmd.Parameters.Add( "@Region", Region.SelectedItem.Text)
cmd.Parameters.Add( "@Company", Company.Text)
cmd.Parameters.Add( "@EmailAddress", Email_Address.Text)
cmd.Parameters.Add( "@HomePhone", HomePhone.Text)
cmd.Parameters.Add( "@BusinessPhone", BusinessPhone.Text)
cmd.Parameters.Add( "@MobilePhone", MobilePhone.Text)
cmd.Parameters.Add( "@Password", Password)
cmd.Connection.Open()
AssociateRef = cmd.ExecuteScalar
cmd.Connection.Close()
doUploadCV
panelSendEmail.Visible = false
panelMailSent.Visible = true
Response.AddHeader("Refresh","5;url=index.html")
End Sub
</script>