VB icon

SQL and ASP

Email
Submitted on: 1/6/2015 12:53:00 PM
By: Hohl David (from psc cd)  
Level: Beginner
User Rating: By 5 Users
Compatibility: ASP (Active Server Pages), VbScript (browser/client side)
Views: 1299
 
     SQL and ASP: Here I have listed same important SQL-Statement. and same functions for connect to Database. By my samples I don't use: follow ADO Command: -add -update ... only SQL (is faster and better to read) I dont't check why so much programmer use not the SQL-Staetment
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
'**************************************
' Name: SQL and ASP
' Description:SQL and ASP:
Here I have listed same important SQL-Statement.
and same functions for connect to Database.
By my samples I don't use:
follow ADO Command:
	-add
	-update
	...
only SQL (is faster and better to read)
I dont't check why so much programmer use not the SQL-Staetment
' By: Hohl David (from psc cd)
'**************************************

'SELECT with Array
Dim arrstrZipcode()
Dim i
Set rec = Server.CreateObject("ADODB.Recordset")
strSQL = "SELECT zipcode FROM ZIPCODES WHERE Countrycode = 'AUT'"
set rec = objConn.Execute(strSQL)
if not rec.eof then
	while not rec.eof
		redim preserve arrstrZipcode(i)
		arrstrZipcode(i) = rec.fields("zipcode")
		rec.movenext
		i = i + 1		
	wend
else
	strError = "Nothing found"
end if
' 覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧
'UPDATE 
strFirstname = ReplaceUnletters(Request.form("txtFirstname"))
iAdressID = Request.Form("txtAdressID")
Set rec = Server.CreateObject("ADODB.Recordset")
strSQL = "Update ADDRESS SET " & _
	 "Firstname = '" & strFirstname & "' " & _
	 "WHERE ZipcodeID = " & iAdressID 
set rec = objConn.Execute(strSQL)
' 覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧	
'INSERT
strFirstname = ReplaceUnletters(Request.form("txtFirstname"))
strLastname = ReplaceUnletters(Request.form("txtFirstname"))
Set rec = Server.CreateObject("ADODB.Recordset")
strSQL = "INSERT INTO ADDRESS (Firstname, Lastname) VALUES ( " & _
	 "'" & strFirstname & "', " & _
	 "'" & strLastname & "')"
set rec = objConn.Execute(strSQL)
' 覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧	
'DELETE
iAddressID = Request.querystring("AdID")
Set rec = Server.CreateObject("ADODB.Recordset")
strSQL = "DELETE FROM ADDRESS WHERE AddressID = " & iAddressID
set rec = objConn.Execute(strSQL)
' 覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧	
' FUNCTIONS
' 覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧
	
function OpenDatabase()
Dim strDatabaseIP, strPW, strUID
	strDatabaseIP = "150.150.100.210"
	strPW = ""
	strUID = "sa"
'SQL-Server
	strConn = "Provider=SQLOLEDB.1;SERVER=" & strDatabaseIP & ";DATABASE=ADDRESS;UID=" & strUID & ";PWD=" & strPW
'MY SQL
strConn = "DRIVER={MySQL ODBC 3.51 Driver};SERVER=" & strDatabaseIP & ";DATABASE=Address;UID=" & strUID & ";PWD=" & strPW & ";OPTION=35;"
	set objConn = server.CreateObject("ADODB.Connection")
	objConn.Open(strConn)
end function
function CloseDatabase()
	objConn.close
	Set objConn = Nothing 
end function
' 覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧
Public Function ReplaceUnLetters(ByVal strReplace)
	strReplace = Replace(strReplace, "'", "''")
	ReplaceUnLetters = strReplace
End Function
' 覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧
 
Function ReplaceNonSpace(strText)
'Here I want replace HTMLSPACE WITH normal space, but the insert into the Planet Source code replace the HTML TAG excuse
	ReplaceNonSpace = Replace(strText, " ", " " )
End Function


Other 3 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.