dear all pro programmer here, im totally new in here, and i might dont know how to correctly as a question here..
if i may ask for help, could u pls here here here... im having problem with simple asp with oop structure...
help me with function savedata pls. when run,
call savedata("insert","test_","name, id","lalala, 222","User_ID=3")
got error :
INSERT INTO test_ (name, id) VALUES (lalala, 222)
... Microsoft VBScript runtime error '800a01a8'
Object required: 'Conn'
<%
function declare_conn(sql,atr)
dim conn, conn_
set conn = Server.CreateObject("ADODB.Connection")
conn = Connect()
set conn_ = Server.CreateObject("ADODB.Recordset")
strConnect = _T("Driver={MySQL ODBC 3.51 Driver};Server=localhost;"
"Database=MyDatabase;User=MyUserName;Password=MyPassword;Option=4;");
if Cstr(atr)="open" then
conn_.CursorLocation = adUseClient
conn_.Open sql, conn, 3, 2
set conn_.ActiveConnection = nothing
set declare_conn=conn_
else if Cstr(atr)="exec" then
conn.Open
conn.Execute sql
end if
end if
end function
function calldata(a,b,c,d)
dim conn_string, sql_string
if c<>"" and d<>"" then
sql_string="SELECT "&Cstr(a)&" FROM "&Cstr(b)&" WHERE "&Cstr(c)&" = '"&Cstr(d)&"'"
response.write(sql_string)
else
sql_string="SELECT "&Cstr(a)&" FROM "&Cstr(b)
response.write(sql_string)
end if
set conn_string = Server.CreateObject("ADODB.Recordset")
set conn_string = declare_conn(sql_string,"open")
set calldata = conn_string
end function
function savedata(a,b,c,d,e)
dim conn_string, sql_string, c_, d_, update_string
update_string = ""
if Cstr(a)="insert" then
sql_string="INSERT INTO "&Cstr(b)&" ("&Cstr(c)&") VALUES ("&Cstr(d)&")"
end if
response.write(sql_string)
'response.end
if Cstr(a)="update" then
c_ = split(c,", ",-1)
d_ = split(d,", ",-1)
response.write(c_)
response.end
if ubound(c_) = ubound(d_) then
do while not c_.eof
update_string=update_string&"("&Cstr(c_)&"="&Cstr(d_)&"),"
c_.MoveNext : d_.MoveNext
loop
else
%><script type="text/javascript">alert("save function error: array out of bound");</script> <%
end if
if Cstr(e)<>"" then
sql_string="UPDATE "&Cstr(b)&" SET "&update_string&" WHERE "&Cstr(e)
else
sql_string="UPDATE "&Cstr(b)&" SET "&update_string
end if
end if
'set conn_string = Server.CreateObject("ADODB.Recordset")
call declare_conn(sql_string,"exec")
end function
%>
wht is tht error actually mean? i create a connection to database ADO in
connect()
still, i can run without problem for
calldata()
editing-dwerty_weird
SOrry for the ruckus..
for this question, i find out, tht i missing "Set" for:
set conn=Connect()
sorry for the trouble... but for other question, i having problem with
call savedata("update","test_","name, id","'lalala', 222","bil=1")
it will get error : Microsoft VBScript runtime error '800a01a8' Object required /bkpi-msn/SPPro/function.asp, line 56 –
can anyone help me?
You're missing single quotes in your data . Value for name is a string and should be wrapped in single quotes.
You have already implemented this in calldata() that is why it is working fine. Update the same for savedata too.
Note: This applies for all the string parameters and may apply in some other way (using #) for date / datetime parameters too.
Please use this as a starting point and follow best-practices for development!
Hope this helps!
Vivek
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.