一、Vb6 通过 ADO 连接 MYSQL 数据库
Dim cn As New ADODB.Connection
'hostserver = "127.0.0.1"
'user = "root"
'pwd = "123456"
'dbserver = "backup"
'If cn.State = 1 Then
'
cn.Close
strcn = " DRIVER={MySQL ODBC 5.2 unicode Driver};" & "SERVER=" &
hostserver & "; DATABASE=" & dbserver & ";UID=" & user & ";PWD=" & pwd
& "; OPTION=3"
cn.Open strcn
endif
二、Vb6 调用 Mysql 存储过程
sqlstr = "call Stor_InOutMat('" & selck & "'," & Val(Label20.Caption) & "," & Val(Text10) & ",'"
& czymc & "','" & Trim(Text11) & "'," & czyid & ")"
cn.Execute sqlstr
三、带参数的 Mysql 存储过程
CREATE DEFINER=`root`@`localhost` PROCEDURE `Stor_InOutMat`(IN indeportCode
varchar(30), IN inmateId int,IN Num int,IN InName varchar(20) charset utf8,IN InRemark
varchar(50) charset utf8,IN InUseId int)
BEGIN
set @ServerDT=sysdate();
select count(mateid) into @aa from materialios where trim(Depotcode)=trim(indeportCode) and
mateid=inmateId;
if @aa=0 then /* 无库存记录,直接加一条入仓或出仓记录 */
begin
if
then
insert
num>0
into
materialios(mateid,depotcode,IOSDateTime,AddNum,SubNum,OverNum,UserName,Remark,Use
rId) values(inmateId,indeportCode,@ServerDT,Num,0,Num,InName,InRemark,InUseId);
/* 入
仓 */
else
insert
into
materialios(mateid,depotcode,IOSDateTime,AddNum,SubNum,OverNum,UserName,Remark,Use
rId) values(inmateId,indeportCode,@ServerDT,0,0-Num,Num,InName,InRemark,InUseId);
--
出仓--
end if;
end;
else
/* 以前有库存记录,查询库存量后再出入仓及更改库存量 */
begin
@lasttime
trim(Depotcode)=trim(indeportCode) and mateid=inmateId;
max(ID)
select
into
from
materialios
where
select OverNum into @OverNum from materialios where ID=@lasttime;
/*select max(IOSDateTime)
into @lasttime
trim(Depotcode)=trim(indeportCode) and mateid=inmateId;
from materialios
/* 最后的出入仓时间*/
where
/*select OverNum into @OverNum from materialios where Depotcode=indeportCode
and mateid=inmateId and IOSDateTime=@lasttime;
/* 现有库存量*/
if
num>0
into
materialios(mateid,depotcode,IOSDateTime,AddNum,SubNum,OverNum,UserName,Remark,Use
rId)
values(inmateId,indeportCode,@ServerDT,Num,0,@OverNum+Num,InName,InRemark,InUseId);
/* 入仓 */
insert
then
else
insert
into
materialios(mateid,depotcode,IOSDateTime,AddNum,SubNum,OverNum,UserName,Remark,Use
rId)
values(inmateId,indeportCode,@ServerDT,0,0-Num,@OverNum+Num,InName,InRemark,InUseI
d);
-- 出仓--
end if;
end;
end if;
DROP TEMPORARY TABLE IF EXISTS lstjb;
CREATE TEMPORARY TABLE lstjb SELECT mateid,depotcode,max(iosdatetime) as maxti
from materialios group by mateid,depotcode;
select
sum(overnum)
into
@LastNum
lstjb,materialios
materialios.depotcode=lstjb.depotcode
from
where
and
materialios.mateid=lstjb.mateid
materialios.iosdatetime=lstjb.maxti and materialios.mateid=inmateId;
and
update mate_inf set numbers=@LastNum where Id= inmateId;
END;
http://zhangjin7422.1688.com/
QQ:954486673