Foxtable(狐表)用户栏目专家坐堂 → [求助]一个SQL按钮代码


  共有25618人关注过本帖树形打印复制链接

主题:[求助]一个SQL按钮代码

帅哥哟,离线,有人找我吗?
migold
  1楼 | QQ | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:一尾狐 帖子:447 积分:4572 威望:0 精华:0 注册:2009/1/11 11:00:00
[求助]一个SQL按钮代码  发帖心情 Post By:2009/7/27 14:14:00 [显示全部帖子]

关于:
删除按钮:With e.Form.Controls("MonthDate")
    If .Value IsNot Nothing Then
    Dim s5 As String = CStr(.Value)
    Dim s6 As String
    s6 = s5.SubString(0,7)
    Dim cmd As New SQLCommand
    Dim Count AS Integer
    cmd .CommandText = "DELETE FROM MiMonthTotal where BillDate = '" & s6 & "'"
    cmd.C
    Count= cmd.ExecuteNonQuery()
    Messagebox.Show( "总共删除月结" & Count & "行!")
    End If
End With

执行成功

求助
插入按钮代码:
需要执行的SQL语句:insert into MiMonthTotal (mode,Stor_ID,Stor_Code,Stor_Name,Unit_ID,Unit_Code,Unit_Name,Emp_ID,Emp_Code,Emp_Name,Prod_ProdType,Prod_Back1,BillDate,BillType,Prod_Number1,Prod_Number2,Prod_Number3,DisMoney1,DisMoney2,DisMoney3,CostMoney1,CostMoney2,CostMoney3,ProfitMoney)
select '1' AS 'mode',
 f.s_ID AS 'Stor_ID',f.u_Code AS 'Stor_Code',f.u_Name AS 'Stor_Name',
 '0' AS 'Unit_ID','0' AS 'Unit_Code','0' AS 'Unit_Name',
 '0' AS 'Emp_ID','0' AS 'Emp_Code','0' AS 'Emp_Name',
 e.ProdType AS 'Prod_ProdType',
 '0' AS 'Prod_Back1',
 left(b.billdate,7) AS 'BillDate',left(d.billname,2) AS 'BillType',
 sum(case when billtype2 in ('4','16') then 0 else isnull(Prod_Number,0) end) AS 'Prod_Number1',
 sum(case when billtype2 in ('4','16') then -isnull(Prod_Number,0) else 0 end) AS 'Prod_Number2',
 sum(case when billtype2 in ('4','16') then -isnull(Prod_Number,0) else isnull(Prod_Number,0) end) AS 'Prod_Number3',
 sum(case when billtype2 in ('4','16') then 0 else isnull(DisMoney,0) end) AS 'DisMoney1',
 sum(case when billtype2 in ('4','16') then -isnull(DisMoney,0) else 0 end) AS 'DisMoney2',
 sum(case when billtype2 in ('4','16') then -isnull(DisMoney,0) else isnull(DisMoney,0) end) AS 'DisMoney3',
 sum(case when billtype2 in ('4','16') then 0 else isnull(CostMoney,0) end) AS 'CostMoney1',
 sum(case when billtype2 in ('4','16') then -isnull(CostMoney,0) else 0 end) AS 'CostMoney2',
 sum(case when billtype2 in ('4','16') then -isnull(CostMoney,0) else isnull(CostMoney,0) end) AS 'CostMoney3',
 sum(case when billtype2 in ('4','16') then -(isnull(dismoney,0)-isnull(costmoney,0)) else (isnull(dismoney,0)-isnull(costmoney,0)) end) AS 'ProfitMoney'
from ListSale A
left join (select autoid,unit_id,billtype,billdate,s_Syb,emp_id from masterbill) b on a.bill_id=b.autoid
left join (select s_id,u_Code,u_Name from units) c on b.unit_id=c.s_id
left join (select billtype billtype2,billname from billtype) d on b.billtype=d.billtype2
left join (select s_id,u_Code,u_Name,ProdType,Back1,Back2,Back3 from product) e on a.prod_id=e.s_id
left join (select s_ID,u_Code,u_Name from StorHouse) f on a.Stor_ID = f.s_ID
left join (select s_ID,u_Name from commoninfo where s_class='14')comib on e.Back1 = comib.s_ID
left join (select s_ID,u_Name from commoninfo where s_class='15')comic on e.Back2 = comic.s_ID
left join (select s_ID,u_Name from commoninfo where s_class='16')comid on e.Back3 = comid.s_ID
left join (select s_id,u_Code,u_name from employee) k on b.emp_id = k.s_id
where b.s_Syb = 0 and d.billtype2 in ('15','16','1','4') and left(b.billdate,7) = '2009-06'
GROUP BY f.s_ID,f.u_Code,f.u_Name,e.ProdType,left(b.billdate,7),left(d.billname,2)


 回到顶部
帅哥哟,离线,有人找我吗?
migold
  2楼 | QQ | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:一尾狐 帖子:447 积分:4572 威望:0 精华:0 注册:2009/1/11 11:00:00
  发帖心情 Post By:2009/7/27 14:15:00 [显示全部帖子]

在SQL能执行成功,就是不知按钮代码怎样写


 回到顶部
帅哥哟,离线,有人找我吗?
migold
  3楼 | QQ | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:一尾狐 帖子:447 积分:4572 威望:0 精华:0 注册:2009/1/11 11:00:00
  发帖心情 Post By:2009/7/27 14:31:00 [显示全部帖子]

就是提示,错误


 回到顶部
帅哥哟,离线,有人找我吗?
migold
  4楼 | QQ | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:一尾狐 帖子:447 积分:4572 威望:0 精华:0 注册:2009/1/11 11:00:00
  发帖心情 Post By:2009/7/27 14:33:00 [显示全部帖子]

提示:
编译错误:字符串常量必须以双引号结束

 回到顶部
帅哥哟,离线,有人找我吗?
migold
  5楼 | QQ | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:一尾狐 帖子:447 积分:4572 威望:0 精华:0 注册:2009/1/11 11:00:00
  发帖心情 Post By:2009/7/27 14:34:00 [显示全部帖子]

就是不明白,麻烦老大,给我写一个按钮代码

 回到顶部
帅哥哟,离线,有人找我吗?
migold
  6楼 | QQ | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:一尾狐 帖子:447 积分:4572 威望:0 精华:0 注册:2009/1/11 11:00:00
  发帖心情 Post By:2009/7/27 14:42:00 [显示全部帖子]

你说的,我不太懂,能否直接给个代码


 回到顶部
帅哥哟,离线,有人找我吗?
migold
  7楼 | QQ | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:一尾狐 帖子:447 积分:4572 威望:0 精华:0 注册:2009/1/11 11:00:00
  发帖心情 Post By:2009/7/27 14:52:00 [显示全部帖子]

就是把你调是通过的SQL语句保存在一个文本文件中,将定保存在文件c:\data\inset.txt
cmd.commandtext = filesys.readalltext("c:\data\inset.txt")

这个OK,很好

请问一下,里面有一句,是要变量的,怎样搞:
insert into MiMonthTotal (mode,Stor_ID,Stor_Code,Stor_Name,Unit_ID,Unit_Code,Unit_Name,Emp_ID,Emp_Code,Emp_Name,Prod_ProdType,Prod_Back1,BillDate,BillType,Prod_Number1,Prod_Number2,Prod_Number3,DisMoney1,DisMoney2,DisMoney3,CostMoney1,CostMoney2,CostMoney3,ProfitMoney)
select '1' AS 'mode',
 f.s_ID AS 'Stor_ID',f.u_Code AS 'Stor_Code',f.u_Name AS 'Stor_Name',
 '0' AS 'Unit_ID','0' AS 'Unit_Code','0' AS 'Unit_Name',
 '0' AS 'Emp_ID','0' AS 'Emp_Code','0' AS 'Emp_Name',
 e.ProdType AS 'Prod_ProdType',
 '0' AS 'Prod_Back1',
 left(b.billdate,7) AS 'BillDate',left(d.billname,2) AS 'BillType',
 sum(case when billtype2 in ('4','16') then 0 else isnull(Prod_Number,0) end) AS 'Prod_Number1',
 sum(case when billtype2 in ('4','16') then -isnull(Prod_Number,0) else 0 end) AS 'Prod_Number2',
 sum(case when billtype2 in ('4','16') then -isnull(Prod_Number,0) else isnull(Prod_Number,0) end) AS 'Prod_Number3',
 sum(case when billtype2 in ('4','16') then 0 else isnull(DisMoney,0) end) AS 'DisMoney1',
 sum(case when billtype2 in ('4','16') then -isnull(DisMoney,0) else 0 end) AS 'DisMoney2',
 sum(case when billtype2 in ('4','16') then -isnull(DisMoney,0) else isnull(DisMoney,0) end) AS 'DisMoney3',
 sum(case when billtype2 in ('4','16') then 0 else isnull(CostMoney,0) end) AS 'CostMoney1',
 sum(case when billtype2 in ('4','16') then -isnull(CostMoney,0) else 0 end) AS 'CostMoney2',
 sum(case when billtype2 in ('4','16') then -isnull(CostMoney,0) else isnull(CostMoney,0) end) AS 'CostMoney3',
 sum(case when billtype2 in ('4','16') then -(isnull(dismoney,0)-isnull(costmoney,0)) else (isnull(dismoney,0)-isnull(costmoney,0)) end) AS 'ProfitMoney'
from ListSale A
left join (select autoid,unit_id,billtype,billdate,s_Syb,emp_id from masterbill) b on a.bill_id=b.autoid
left join (select s_id,u_Code,u_Name from units) c on b.unit_id=c.s_id
left join (select billtype billtype2,billname from billtype) d on b.billtype=d.billtype2
left join (select s_id,u_Code,u_Name,ProdType,Back1,Back2,Back3 from product) e on a.prod_id=e.s_id
left join (select s_ID,u_Code,u_Name from StorHouse) f on a.Stor_ID = f.s_ID
left join (select s_ID,u_Name from commoninfo where s_class='14')comib on e.Back1 = comib.s_ID
left join (select s_ID,u_Name from commoninfo where s_class='15')comic on e.Back2 = comic.s_ID
left join (select s_ID,u_Name from commoninfo where s_class='16')comid on e.Back3 = comid.s_ID
left join (select s_id,u_Code,u_name from employee) k on b.emp_id = k.s_id
where b.s_Syb = 0 and d.billtype2 in ('15','16','1','4') and left(b.billdate,7) = '2009-06'
GROUP BY f.s_ID,f.u_Code,f.u_Name,e.ProdType,left(b.billdate,7),left(d.billname,2)

 回到顶部
帅哥哟,离线,有人找我吗?
migold
  8楼 | QQ | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:一尾狐 帖子:447 积分:4572 威望:0 精华:0 注册:2009/1/11 11:00:00
  发帖心情 Post By:2009/7/27 14:52:00 [显示全部帖子]

就是这一句,要加变量

 回到顶部
帅哥哟,离线,有人找我吗?
migold
  9楼 | QQ | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:一尾狐 帖子:447 积分:4572 威望:0 精华:0 注册:2009/1/11 11:00:00
  发帖心情 Post By:2009/7/27 14:52:00 [显示全部帖子]

left(b.billdate,7) = '2009-06'

 回到顶部
帅哥哟,离线,有人找我吗?
migold
  10楼 | QQ | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:一尾狐 帖子:447 积分:4572 威望:0 精华:0 注册:2009/1/11 11:00:00
  发帖心情 Post By:2009/7/27 15:03:00 [显示全部帖子]

这个方法行?,变量每次会变,替换一次后,下一次又是怎样替换

麻烦老大写一下代码

 回到顶部
总数 23 1 2 3 下一页