inetserver asp db:
wrote on 17 dec 2006 in microsoft.public.inetserver.asp.db:
[quoted text, click to view] > hello... can somebody tell what is the error of my codings? coz i want
> to create a search control... this is suppose to be the flow, at first
> run i declare a ServerVariable which is ("Remote_Addr") to detect the
> ipaddress... i also have a textfield in my form which must show the
> "CompName"
>
> then i have a 2tables inside my database.. (1)ipAdd and (2)CompName.. i
I think you have one table "con" with two fields "ipAdd" and "CompName"
[quoted text, click to view] > already input the datas needed. my condition is like this, if
> ServerVariable("Remote_Addr") = ipAdd then,
> i want to show the field of CompName inside the textfield as its
> corresponding value...
>
> what can i do? please check and correct me coz i always experience
> error...
>
[..]
>
> <%
> dim ip
>
> set conn=Server.CreateObject("ADODB.Connection")
> conn.Provider="Microsoft.Jet.OLEDB.4.0"
> conn.Open(Server.Mappath("users.mdb"))
>
> set rs=Server.CreateObject("ADODB.recordset")
> sql="SELECT DISTINCT ipAdd FROM com"
> rs.Open sql,conn
>
> username=request.form("username")
> ip=request.ServerVariables("REMOTE_ADDR")
> %>
> <form method="post">
> Username <input type="text" name="username"
> value="<%=rs.Fields("CompName")%>">
Is just a random record's field, from any IP stored, ok?
Because only now you go looking for the right one,
and incorrectly coded:
[quoted text, click to view] > <% do until rs.EOF
>
> if rs.fields("ipAdd")=ip then
> username=response.Write(rs.fields("CompName"))
response.Write() does not return a value
[quoted text, click to view] > end if
> rs.MoveNext
> loop
> rs.Close
> set rs=Nothing %>
> </form>
>
> </body>
> </html>
I think it is a strange way of doing things.
You do not need a record set for this.
[in fact record sets are seldom realy "needed"]
Why not have the jet engine look for the right IP?
Expecting one username per ip is a wrong, if you do this on internet,
where some ip's are shared among thousands, and users change IP's or even
locations frequently.
However if you are on an intranet, and users do not work on eachothers
line, why not [not tested]:
============================
<%
set conn=Server.CreateObject("ADODB.Connection")
conn.Open "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=" &
Server.MapPath("users.mdb") & ";"
sql="SELECT ipAdd,CompName FROM com WHERE ipAdd = " &
request.ServerVariables("REMOTE_ADDR")
set mD = conn.Execute(sql)
if not mD.EOF then
username = mD("CompName")
''' Just takes the first one with the right IP,
''' that comes up, if not unique.
else
username = ""
end if
%>
<form method="post">
Username
<input name="username" value="<% = username %>">
.....
==============================
--
Evertjan.
The Netherlands.