我使用query控件时可以这样用
with Query1.SQL do
begin
clear;
Append('insert into dy_client_info(client_code,client_name,client_dress,');
Append('linkman,FUNC_KEYWORD,func_depict,office_code,technician,re) ');
append('values(:client_code,:client_name,:client_dress,:linkman,');
append(':func_keyword,:func_depict,:office_code,:technician,:re)');
end;
with query1 do
begin
ParamByName('client_code').asstring:=edit1.text;
parambyname('client_name').AsString:=edit2.Text;
parambyname('client_dress').AsString :=edit5.Text;
parambyname('linkman').AsString:=edit3.Text;
parambyname('func_keyword').AsString:=edit6.Text;
parambyname('func_depict').AsBlob:=StringStream1.DataString;
parambyname('office_code').asstring:=office_code;
parambyname('technician').AsString:=edit4.Text;
parambyname('re').AsBlob:=stringstream2.DataString;
end;
但使用ADOQUERY控件时,不能使用了,哪位大侠可知道应使用,望告知。
with Query1.SQL do
begin
clear;
Append('insert into dy_client_info(client_code,client_name,client_dress,');
Append('linkman,FUNC_KEYWORD,func_depict,office_code,technician,re) ');
append('values(:client_code,:client_name,:client_dress,:linkman,');
append(':func_keyword,:func_depict,:office_code,:technician,:re)');
end;
with query1 do
begin
ParamByName('client_code').asstring:=edit1.text;
parambyname('client_name').AsString:=edit2.Text;
parambyname('client_dress').AsString :=edit5.Text;
parambyname('linkman').AsString:=edit3.Text;
parambyname('func_keyword').AsString:=edit6.Text;
parambyname('func_depict').AsBlob:=StringStream1.DataString;
parambyname('office_code').asstring:=office_code;
parambyname('technician').AsString:=edit4.Text;
parambyname('re').AsBlob:=stringstream2.DataString;
end;
但使用ADOQUERY控件时,不能使用了,哪位大侠可知道应使用,望告知。
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, ADODB, StdCtrls, ExtCtrls;type
TForm1 = class(TForm)
ADOQuery1: TADOQuery;
Edit1: TEdit;
Label1: TLabel;
Edit2: TEdit;
Label2: TLabel;
Label3: TLabel;
Edit3: TEdit;
Button1: TButton;
Label4: TLabel;
Timer1: TTimer;
Memo1: TMemo;
ADOConnection1: TADOConnection;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
private
function Isp(const telnum:string):string;
Function GetModuleISP(const DestAddr:string):string;
Function Connect():string;
procedure sendMessage();
procedure getmodule();
Procedure RevMessage();
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}function Sms_Connect ( pcServerName: pchar; wPort: integer; pcUsrname: pchar; pcPassWord: pchar;wUserId: integer ): integer; StdCall; external 'SmsApi211.dll';
function Sms_Cleanup :integer;StdCall; external 'smsapi211.dll';
function Get_SendResult( messageID: pchar; donetime: pchar; isdnnum: pchar; destaddr: pchar; wresult:pinteger ): integer; stdcall; external 'smsapi211.dll';
function Sms_Send( pcDestAddr: pchar; pcModuleIsdnNum: pchar; ioption: integer; Pmsg: pchar; Pmsgid:pchar; roundtype: integer ): integer; stdcall; external 'smsapi211.dll'
Function Get_RevMsg_Count: integer; stdcall; external 'smsapi211.dll';
Function Get_RevMsg(isdnnum: pchar; souraddr: pchar; msg: pchar): integer; stdcall; external 'smsapi211.dll';
function GetModl( var bDev: integer; var bmodl: integer; bmodltyp: integer; bworktyp: integer; pcIsdnNum:pchar ): integer; stdcall; external 'smsapi211.dll';
Function ReleaseModl ( bDev : integer ; bModl : integer ): integer; StdCall ; external 'SmsApi211.dll';function Tform1.Isp(const telnum:string):string;
begin
if telnum[3] in ['0','1','2','3','4'] then
result:='联通'
else result:='移动';
end;Function Tform1.GetModuleISP(const DestAddr:string):string;
begin
adoquery1.Close;
adoquery1.SQL.Clear;
adoquery1.SQL.Add('SELECT top 1 * FROM modulenum WHERE ((times=(SELECT MIN(times) FROM modulenum WHERE isp ='''+ISP(DestAddr)+''')) AND (isp ='''+ISP(DestAddr)+'''))');
adoquery1.Open; if adoquery1.RecordCount=0 then
begin
adoquery1.Close;
adoquery1.SQL.Clear;
adoquery1.SQL.Add('SELECT top 1 * FROM modulenum WHERE (times=(SELECT MIN(times) FROM modulenum ))');
adoquery1.Open; end;
result:=adoquery1.FieldValues['IsdnNum'];end;procedure TForm1.GetModule();
var
i,bDev,bModl:integer ;
ModuleIsdn:pchar;
status:integer;
begin
//-------------------------------------------
adoquery1.Close;
adoquery1.SQL.Clear;
adoquery1.SQL.Add('DELETE FROM modulenum');
adoquery1.ExecSQL; //清空表ModuleNum内容
//--------------------------------------------
new(ModuleIsdn);GetMem(ModuleIsdn,20);
bDev:=0;
for i:=0 to 7 do //如获得模块成功,写入数据库
begin
bModl:=i;
status:=GetModl(bDev,bModl,0,4,ModuleIsdn);
if status=0 then
begin
ModuleIsdn[11]:=#0;
adoquery1.Close;
adoquery1.SQL.Clear;
adoquery1.SQL.Add('INSERT INTO modulenum VALUES(:_Num,:_IsdnNum,:_ISP,0)');
adoquery1.Parameters.ParamByName('_num').Value:=i+1;
adoquery1.Parameters.ParamByName('_IsdnNum').Value:=StrPas(ModuleIsdn);
adoquery1.Parameters.ParamByName('_ISP').Value:=ISP(ModuleIsdn);
adoquery1.ExecSQL;
Memo1.Lines.Add('[ '+datetimetostr(now)+ ' ] 检测模块'+inttostr(i)+':检测成功,中国'+ISP(ModuleIsdn)+ModuleIsdn);
end
else
Memo1.Lines.Add('[ '+datetimetostr(now)+ ' ] 检测模块'+inttostr(i)+':未检测到SIM卡!');
end;
end;
procedure TForm1.sendMessage();
var
ioption,i:integer;
msg,str,destaddr,MsgID,username,ModuleIsdn:string;
status:integer;
begin
//=============查找待发短信=====================
adoquery1.Close;
adoquery1.SQL.Clear;
adoquery1.SQL.Add('SELECT TOP 1 * FROM outbox WHERE sendtime <= '''+datetimetostr(now)+'''');
adoquery1.Prepared;
adoquery1.Open;//==================================
if adoquery1.RecordCount>0 then
begin
msg:=adoquery1.FieldValues['msg'];
destaddr:=adoquery1.FieldValues['destaddr'];
MsgID:=adoquery1.FieldValues['MsgID'];
username:=adoquery1.FieldValues['username'];
ModuleIsdn:=GetModuleISP(DestAddr);adoquery1.Close;
adoquery1.SQL.Clear;
adoquery1.SQL.Add('update outbox set times=times+1 where msgID='''+MsgID+'''');
adoquery1.Prepared;
adoquery1.ExecSQL;i:=0;ioption:=0;
while i<=length(msg) do
begin
if ord(msg[i])>127 then
begin
iOption:=1;
break;
end;
i:=i+1;
end;
status:=sms_send(pchar(destaddr), //发送地址
pchar(ModuleIsdn), //选择模块
iOption, //编码格式
pchar(msg), // 短消息内容
pchar(MsgID), //短消息id
2); //路由格式
case status of
0:str:='发送至服务器成功!'+'[0x0000]';
1:str:='无法连接服务器!'+'[0x0001]';
3:str:='发送至服务器失败!'+'[0x0003]';
4:str:='接收来自服务器的消息失败!'+'[0x0004]';
5:str:='网络忙!'+'[0x0005]';
$4004:str:='没有可用模块!'+'[0x4004]';
$4005:str:='无效编码方案!'+'[0x4005]';
$4006:str:='无效目标地址!'+'[0x4006]';
$4007:str:='短消息内容不能为空!'+'[40x007]';
$4008:str:='无效的路由类型!'+'[4x008]';
$4009:str:='无效的手机号码!'+'[4x009]';
$ff:str:='未知错误,发送失败!'+'[0xFF]';
end;
Memo1.Lines.Add('[ '+datetimetostr(now)+' ] 发送短消息:'+str+'.用户'+username+',目标'+destaddr+',模块'+ModuleIsdn+',MsgID'+MsgID);
adoquery1.Close;
adoquery1.SQL.Clear;
adoquery1.SQL.Add('SELECT * FROM outbox WHERE MsgID = '''+MsgId+'''');
adoquery1.Prepared;
adoquery1.Open;
if (status=0) or(adoquery1.FieldValues['times']=10)then
begin
if adoquery1.FieldValues['times']=10 then
Memo1.Lines.Add('[ '+datetimetostr(now)+' ] 丢弃短消息:'+str+'.用户'+username+',目标'+destaddr+',模块'+ModuleIsdn+',MsgID'+MsgID+','+str);
adoquery1.Close;
adoquery1.SQL.Clear;
adoquery1.SQL.Add('insert into sentbox values(:_username,:_msgID,:_msg,:_DestAddr,:_IsdnNum,:_Sendtime,:_Status)');
adoquery1.Parameters.ParamByName('_username').Value:=username;
adoquery1.Parameters.ParamByName('_MsgID').Value:=MsgID;
adoquery1.Parameters.ParamByName('_msg').Value:=msg;
adoquery1.Parameters.ParamByName('_DestAddr').Value:=DestAddr;
adoquery1.Parameters.ParamByName('_IsdnNum').Value:=ModuleIsdn;
adoquery1.Parameters.ParamByName('_Sendtime').Value:=datetimetostr(now);
adoquery1.Parameters.ParamByName('_Status').Value:=str;
adoquery1.Prepared;
adoquery1.ExecSQL;
//----------------------------
adoquery1.Close;
adoquery1.SQL.Clear;
adoquery1.SQL.Add('Delete From Outbox where MsgID=:_MsgID');
adoquery1.Parameters.ParamByName('_MsgID').Value:=MsgID;
adoquery1.ExecSQL;
end ;end;
end;
var
IsdnNum,SourAddr,Msg:pchar;
begin
new(IsdnNum); new(SourAddr);new(Msg);
getmem(IsdnNum,12); getmem(SourAddr,12);getmem(Msg,141);
if Get_RevMsg(IsdnNum,SourAddr,Msg)=1 then
begin
IsdnNum[11]:=#0; SourAddr[11]:=#0;
adoquery1.Close;
adoquery1.SQL.Clear;
adoquery1.SQL.Add('insert into inbox values(:_IsdnNum,:_SourAddr,:_Msg,:_Revtime)');
adoquery1.Parameters.ParamByName('_IsdnNum').Value:=StrPas(IsdnNum);
adoquery1.Parameters.ParamByName('_SourAddr').Value:=StrPas(SourAddr);
adoquery1.Parameters.ParamByName('_msg').Value:=StrPas(msg);
adoquery1.Parameters.ParamByName('_Revtime').Value:=datetimetostr(now);
adoquery1.Prepared;
adoquery1.ExecSQL;
Memo1.Lines.Add('[ '+datetimetostr(now)+' ] 收到短消息:源号码'+SourAddr+',模块'+IsdnNum) ;
end;
end;
Function TForm1.Connect():string;
var
status:integer ;
str:string;
begin
status:=Sms_Connect(pchar(edit1.text),strtoint(edit2.Text),nil,nil,$10000000);
case status of
0: str:='连接成功!'+'[0x0000]';
1: str:='发送到server失败!'+'[0x0001]';
2: str:='端口参数错误!'+'[0x0002]' ;
3: str:='发送到服务器失败!' +'[0x0003]';
4: str:='接收服务器消息失败!'+'[0x0004]' ;
5: str:='网络忙!'+'[0x0005]' ;
$1003: str:='USERID错误!'+'[0x1003]' ;
$1004: str:='连接已建立!'+'[0x1004]' ;
$1005: str:='程序已初始化!'+'[0x1005]' ;
$1006: str:='用户已登录!'+'[0x1006]' ;
$1007: str:='用户资源已满!'+'[0x1007]' ;
$1008: str:='客户端版本错误!' +'[0x1008]' ;
$ff: str:='未知错误,连接服务器失败!'+'[0xFF]' ;
end;
result:=str;
end;procedure TForm1.Button1Click(Sender: TObject);
var
sql_Server_name,ConnStr:string;
begin
sms_Cleanup;
adoconnection1.Connected:=false;
Memo1.Clear;
Memo1.Lines.Add('[ '+datetimetostr(now)+' ] 正在连接短信息设备...:');
Memo1.Lines.Add('[ '+datetimetostr(now)+' ] 连接短信息设备:'+Connect);if pos('成功',Memo1.Lines[1])<>0 then
begin
Memo1.Lines.Add('[ '+datetimetostr(now)+ ' ] 正在连接数据库服务器...:');
ADOConnection1.ConnectionString:='Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=SMS;Data Source='+edit3.Text;
try
adoconnection1.Connected:=true;
adoquery1.Connection:=adoconnection1;
Memo1.Lines.Add('[ '+datetimetostr(now)+ ' ] 连接数据库服务器:连接成功!');
except
Memo1.Lines.Add('[ '+datetimetostr(now)+ ' ] 连接数据库服务器:连接失败!');
end;
end;
if adoconnection1.Connected=true then
begin
GetModule;
timer1.Enabled:=true;
end;end;
procedure TForm1.Button2Click(Sender: TObject);
begin
SendMessage;
end;procedure TForm1.Button3Click(Sender: TObject);
begin
RevMessage()
end;procedure TForm1.Timer1Timer(Sender: TObject);
begin
sendmessage;
revmessage;
end;end.
用query只要把sql语句赋值给query的sql属性就可以了。
adoquery1.sql.add('你的sql语句')
谢谢
谢谢