populate / create checkbox list by restriving data from oracle database

eagle_ea
eagle_ea used Ask the Experts™
on
Please provide code for connecting to oracle database and creating and  populating a checkbox list with the vbscript in HTML.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
rejoinderManager, IT
Top Expert 2008

Commented:
Here is a rough example on connecting to Oracle and getting a result set back from the database.  In this example, the loop checks if a field has an option value of "1" which would check the box.  Again this is just an example to start you off.
<%@LANGUAGE=VBSCRIPT%>
<form>
<%
strDataSource   = "OracleDBase"
strDataUserName = "user"
strDataPassword = "password"

strConnection = "Provider=OraOLEDB.Oracle;Data Source=" & strDataSource & ";User Id=" & strDataUserName & ";Password=" & strDataPassword & ";"

Set conn = Server.CreateObject("ADODB.Connection")
conn.Open strConnection

Set rs = Server.CreateObject("ADODB.recordset")
strSQL = "SELECT * FROM myTable"
rs.open strSQL, conn, 3,3

rs.MoveFirst
WHILE NOT rs.EOF
	if rs("myFieldCheckedOrNot") = 1 then
		strChecked = "checked "
	else
		strChecked = ""
	end if
	response.write "<input type=""checkbox"" name=""checkbox01"" value=""" & rs("myField") & """ " & strChecked & "/> " & rs("myField") & "<br />"
	rs.MoveNext
WEND

rs.Close
Set rs = Nothing

conn.Close
Set conn = Nothing
%>
</form>

Open in new window

Author

Commented:
i used the above code and nothing seem to be loading. i dont get any error either.

am I missing something? instead of in the form, can i do it as part of the page onload event?

Author

Commented:
i'm doing this on a HTML file
response.write - will it work on html?
rejoinderManager, IT
Top Expert 2008

Commented:
I see, the above will not work then.  If the page extension were changed to .asp instead of ".htm" or ".html" you would be good to go.  HTML has little dynamic functionality sorry.

Commented:
Oracle connection method
Dim connection, connectionString, theCommand, commandString
connectionString = "DRIVER={Microsoft ODBC for Oracle};SERVER=oracle_server;User Id=user;Password=password;"
Set connection = CreateObject("ADODB.Connection")
Set theCommand = CreateObject("ADODB.Command")
connection.Open connectionString
Commented:
Another example
Dim strCon

strCon = “Driver={Microsoft ODBC for Oracle}; ” & _
         “CONNECTSTRING=(DESCRIPTION=” & _
         “(ADDRESS=(PROTOCOL=TCP)” & _
         “(HOST=Server_Name)(PORT=1521))” & _
         “(CONNECT_DATA=(SERVICE_NAME=DB_Name))); uid=system;pwd=system;”

Dim oCon: Set oCon = WScript.CreateObject(“ADODB.Connection”)
Dim oRs:  Set oRs  = WScript.CreateObject(“ADODB.Recordset”)
oCon.Open strCon

Set oRs = oCon.Execute(“SELECT name from v$database”)

While Not oRs.EOF
   WScript.Echo oRs.Fields(0).Value
   oRs.MoveNext
Wend
oCon.Close

Set oRs = Nothing
Set oCon = Nothing

Open in new window

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial