以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  [求助]一个SQL按钮代码  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=3711)

--  作者:migold
--  发布时间:2009/7/27 14:14:00
--  [求助]一个SQL按钮代码

关于:
删除按钮: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
--  发布时间:2009/7/27 14:15:00
--  

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


--  作者:狐狸爸爸
--  发布时间:2009/7/27 14:16:00
--  

呵呵,不是一样的吗?
cmd .CommandText  = "Inser 语句"


--  作者:migold
--  发布时间:2009/7/27 14:31:00
--  

就是提示,错误


--  作者:狐狸爸爸
--  发布时间:2009/7/27 14:33:00
--  
做成存储过程调用算了。
--  作者:migold
--  发布时间:2009/7/27 14:33:00
--  
提示:
编译错误:字符串常量必须以双引号结束
--  作者:migold
--  发布时间:2009/7/27 14:34:00
--  
就是不明白,麻烦老大,给我写一个按钮代码
--  作者:狐狸爸爸
--  发布时间:2009/7/27 14:37:00
--  

那就是代码语法错误,字符串太长,难免出错,慢慢查。
要不索性整个保存为一个文本文件,或者保存在某个备注字段中,然后读取调用


--  作者:migold
--  发布时间:2009/7/27 14:42:00
--  

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


--  作者:狐狸爸爸
--  发布时间:2009/7/27 14:44:00
--  
就是把你调是通过的SQL语句保存在一个文本文件中,将定保存在文件c:\\data\\inset.txt
cmd.commandtext = filesys.readalltext("c:\\data\\inset.txt")

当然,用存储过程会更好。

[此贴子已经被作者于2009-7-27 14:45:14编辑过]