home *** CD-ROM | disk | FTP | other *** search
- <%
- sub DoDropDown (Name, SQLString,IDField, NameField, SelectedValue)
- dim conn, rstemp
- set Conn=server.createobject("adodb.connection")
-
- '******************************************************************************
- 'You can put the Connection parameters into application variables if you want!!
- '******************************************************************************
- ' conn.open Application("DSN"), Application("uid"), Application("pwd")
- conn.open "TESTCOMBO", "Admin", ""
-
- %><select id = "<%=Name%>" name = "<%=Name%>"><%
-
- set rstemp=conn.execute(sqlString)
- while not rstemp.eof%>
- <option value="<%=rstemp(IDField)%>"<%
- if rstemp(IDField) = SelectedValue then
- %> selected=true <%
- end if
- %> > <%=rstemp(NameField)%><%
- rstemp.movenext
- wend
- rstemp.close
- set rstemp = nothing
- conn.close
- set conn = nothing
- end sub
-
- Function CreateMaxIDExt(TableName1, FieldName1, FieldName2, FieldValue2)
- Dim strSQL, Retries, CurrentTry, ConnTemp, RsTemp , CurrentMax, MustRetry
- Retries = 50
- CurrentTry = 0
- MustRetry = True
- set ConnTemp=server.createobject("adodb.connection")
-
- '******************************************************************************
- 'You can put the Connection parameters into application variables if you want!!
- '******************************************************************************
- ' ConnTemp.open Application("DSN"), Application("uid"), Application("pwd")
- ConnTemp.open "TESTCOMBO", "Admin", ""
-
- On Error Resume Next
- While MustRetry
- CurrentMax = GetMaxNum(TableName1, FieldName1) + 1
- strSQL = "INSERT INTO " & TableName1 & " (" & FieldName1 & ", " & FieldName2 & ") VALUES (" & CurrentMax & ", "& FieldValue2 &")"
- Set RsTemp = ConnTemp.Execute (strSQL)
- if Err.Number <> 0 then
- CurrentTry = CurrentTry + 1
- if CurrentTry >= Retries then
- MustRetry = False
- CreateMaxIDExt = -1
- Response.Write("Couldn't add to table '"& TableName1 &"', field1 '"& FieldName1 &"', Field2 '"& FieldName2 &"' -> Value "& FieldValue2 &", Value '"& CurrentMax &"', Retried "& CurrentTry &" times.<BR>")
- Response.Write("Error Description:" & Err.Description & "<BR>Err Number:" & Err.Number & "<BR><BR>")
- response.write ("SQL : " & strSQL & "<BR>")
- Response.End
- Exit Function
- end if
- Err.Clear
- else
- MustRetry = False
- end if
- Wend
- CreateMaxIDExt = CurrentMax
- Exit Function
- End Function
-
-
- Function GetMaxNum(TableName, FieldName)
- dim conntemp2, rstemp2, sqltemp2
- set conntemp2=server.createobject("adodb.connection")
-
-
- '******************************************************************************
- 'You can put the Connection parameters into application variables if you want!!
- '******************************************************************************
- ' connTemp2.open Application("DSN"), Application("uid"), Application("pwd")
- ConnTemp2.open "TESTCOMBO", "Admin", ""
-
- sqltemp2= "SELECT Max("& FieldName &") FROM "& TableName
- set rstemp2=conntemp2.execute(SQLTemp2)
- if not rstemp2.eof then
- GetMaxNum = iif(isnull(rstemp2(0)),0,rstemp2(0))
- else
- GetMaxNum = 0
- end if
- set rstemp2 = nothing
- set conntemp2 = nothing
- End Function
-
- Function iif(CheckThis, ValTrue, ValFalse)
- if CheckThis then
- iif=ValTrue
- else
- iif=ValFalse
- end if
- End Function
-
- %>