R
rongercao
Unregistered / Unconfirmed
GUEST, unregistred user!
我写了一个asp组件,用于接收asp传来的数据,并保存进数据库中。请大家给看看为什么不行?
函数为,第一个 参数为连接字符串,
第二个到第四个分别为(字段=值)形式
返回值为整型
form2中有adoconnection和adotable控件
function Tdb_test.test(const connect_str, Param1, Param2, Param3,
Param4: WideString): SYSINT;
begin
result:=0;
try
form2.adoc.ConnectionString:=connect_str;
form2.adoc.Connected:=true;
form2.adoc.Open;
except
result:=1
end;
try
form2.tb.Connection:=form2.adoc;
form2.tb.TableName:='test';
form2.tb.Active:=true;
form2.tb.Append;
form2.tb.FieldByName(copy(Param1,1,pos('=',Param1)-1)).Value:=copy(Param1,pos('=',Param1)+1,length(Param1)-pos('=',Param1)-1);
form2.tb.FieldByName(copy(Param2,1,pos('=',Param2)-1)).Value:=copy(Param2,pos('=',Param2)+1,length(Param2)-pos('=',Param2)-1);
form2.tb.FieldByName(copy(Param3,1,pos('=',Param3)-1)).Value:=copy(Param3,pos('=',Param3)+1,length(Param3)-pos('=',Param3)-1);
form2.tb.FieldByName(copy(Param4,1,pos('=',Param4)-1)).Value:=copy(Param4,pos('=',Param4)+1,length(Param4)-pos('=',Param4)-1);
form2.tb.Post;
except
result:=2
end;
end;
测试页
<HTML>
<BODY>
<TITLE> Testing Delphi ASP </TITLE>
<CENTER>
<H3> You should see the results of your Delphi Active Server method below </H3>
</CENTER>
<HR>
<%
dim connectstr
connectstr= "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=cao;Data Source=服务器名"
dim i
Set DelphiASPObj = Server.CreateObject("Project1.test_db")
i =
DelphiASPObj.test(connectstr,"p1=xxx","p2=123232","p3=4444","p4=12323")
response.write(i)
%>
<HR>
</BODY>
</HTML>
执行顺利,但是总是在保存数据的时候出错,也就是返回值为2。请高手帮忙解答,在线等待!
函数为,第一个 参数为连接字符串,
第二个到第四个分别为(字段=值)形式
返回值为整型
form2中有adoconnection和adotable控件
function Tdb_test.test(const connect_str, Param1, Param2, Param3,
Param4: WideString): SYSINT;
begin
result:=0;
try
form2.adoc.ConnectionString:=connect_str;
form2.adoc.Connected:=true;
form2.adoc.Open;
except
result:=1
end;
try
form2.tb.Connection:=form2.adoc;
form2.tb.TableName:='test';
form2.tb.Active:=true;
form2.tb.Append;
form2.tb.FieldByName(copy(Param1,1,pos('=',Param1)-1)).Value:=copy(Param1,pos('=',Param1)+1,length(Param1)-pos('=',Param1)-1);
form2.tb.FieldByName(copy(Param2,1,pos('=',Param2)-1)).Value:=copy(Param2,pos('=',Param2)+1,length(Param2)-pos('=',Param2)-1);
form2.tb.FieldByName(copy(Param3,1,pos('=',Param3)-1)).Value:=copy(Param3,pos('=',Param3)+1,length(Param3)-pos('=',Param3)-1);
form2.tb.FieldByName(copy(Param4,1,pos('=',Param4)-1)).Value:=copy(Param4,pos('=',Param4)+1,length(Param4)-pos('=',Param4)-1);
form2.tb.Post;
except
result:=2
end;
end;
测试页
<HTML>
<BODY>
<TITLE> Testing Delphi ASP </TITLE>
<CENTER>
<H3> You should see the results of your Delphi Active Server method below </H3>
</CENTER>
<HR>
<%
dim connectstr
connectstr= "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=cao;Data Source=服务器名"
dim i
Set DelphiASPObj = Server.CreateObject("Project1.test_db")
i =
DelphiASPObj.test(connectstr,"p1=xxx","p2=123232","p3=4444","p4=12323")
response.write(i)
%>
<HR>
</BODY>
</HTML>
执行顺利,但是总是在保存数据的时候出错,也就是返回值为2。请高手帮忙解答,在线等待!