dlongnecker
MIS
Hello!
I'm trying to build a helper application for me and work on some ASP.NET skills at the same time. I frequently build forms, surveys, etc. in ASP and am trying to avoid the repetition of creating the variable, cleaning up the data, and creating the SQL statement for each project.
I decided to create a ASP.NET application that would upload a plain text file of the form values I used. For example:
From here, it would open a StreamReader and ReadLine() each line into a Do Loop to build my information. However, my problem lies in how the loop works. There's always an empty record at the bottom. While it's not hard to clean up (much faster than what it takes to build all of this), I'd still like to see if I can perfect the program. Here's the code to build the first part of the application.
This works great! It spits out information like:
However, the final entry, rather, the "", shows up.
Is there another way to write the loop statement? Perhaps a better way than ReadLine()'ing the text file. I wanted to keep it simple so I could put this out to some of the other users in our organization...
Ideas, suggestions?
Thanks in advance!
-David
---
David R. Longnecker
CCNA, MCSA, Network+, A+
Management Information Services
Wichita Public Schools, USD 259
I'm trying to build a helper application for me and work on some ASP.NET skills at the same time. I frequently build forms, surveys, etc. in ASP and am trying to avoid the repetition of creating the variable, cleaning up the data, and creating the SQL statement for each project.
I decided to create a ASP.NET application that would upload a plain text file of the form values I used. For example:
Code:
Name
Address
City
State
ZIPCode
Phone
Email
From here, it would open a StreamReader and ReadLine() each line into a Do Loop to build my information. However, my problem lies in how the loop works. There's always an empty record at the bottom. While it's not hard to clean up (much faster than what it takes to build all of this), I'd still like to see if I can perfect the program. Here's the code to build the first part of the application.
Code:
' Open the Stream and Text File
objStreamReader = File.OpenText(strFileName)
' Begin the Do Loop
Do
' Read line of text file.
strFormName = objStreamReader.ReadLine()
' Create Dim line
Response.Write("Dim str" & strFormName & "<br>")
' Create Request.Form Line (pull data line)
Response.Write("str" & strFormName & " = Request.Form("" & strFormName & "")<br>")
' Create Trim whitespace line
Response.Write("str" & strFormName & " = Trim(str" & strFormName & ")<br>")
' Create Replace quote line
Response.Write("str" & strFormName & " = Replace(str" & strFormName & ", "'", "''")<br>")
' Line break
Response.Write("<br>")
' Loop until nothing else shows up.
Loop Until strFormName = ""
' Close stream and clean out variable
objStreamReader.Close()
objStreamReader = Nothing
This works great! It spits out information like:
Code:
Dim strName
strName = Request.Form("Name")
strName = Trim(strName)
strName = Replace(strName, "'", "''")
strSQL = "INSERT INTO <TABLENAME> (strName,strAddress,strCity,strState,strZIPCode,strPhone,strFax,strAge,strGender,strIncome,strEthnic,strEducation,str,) VALUES ("
strSQL = strSQL & "'" & strName & "'"
strSQL = strSQL & ", "
strSQL = strSQL & ");"
However, the final entry, rather, the "", shows up.
Code:
Dim str
str = Request.Form("")
str = Trim(str)
str = Replace(str, "'", "''")
strSQL = strSQL & "'" & str & "'"
strSQL = strSQL & ", "
strSQL = strSQL & ");"
Is there another way to write the loop statement? Perhaps a better way than ReadLine()'ing the text file. I wanted to keep it simple so I could put this out to some of the other users in our organization...
Ideas, suggestions?
Thanks in advance!
-David
---
David R. Longnecker
CCNA, MCSA, Network+, A+
Management Information Services
Wichita Public Schools, USD 259