Foxtable(狐表)用户栏目专家坐堂 → [求助]


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

主题:[求助]

美女呀,离线,留言给我吧!
danwenxie
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:婴狐 帖子:36 积分:419 威望:0 精华:0 注册:2013/11/25 11:08:00
[求助]  发帖心情 Post By:2014/8/21 10:55:00 [显示全部帖子]

请教一下专家,我在执行以下代码时出现一个问题:在同一个代码段中,只能执行一次UPDATE,请专家大师们为我指点迷津!谢谢!谢谢!

代码1:
Dim cmd1 As New SQLCommand
Dim cmd2 As New SQLCommand
cmd1.C
cmd2.C
Dim dt As DataTable

Dim shenheren As String = "test"
Dim danhao As String = e.Form.Controls("danhao").value
Dim shipanshu As Integer
Dim shiyongren As String
Dim quyu As String
Dim diqu As String
Dim bianhao As String


If danhao = "" Then
    Messagebox.show("请输入盘点单号!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
    Return
End If

cmd1.CommandText = "Select * From {Zpandianbiao} Where danhao = '" & danhao & "' "
If cmd1.ExecuteScalar < 1 Then
    Messagebox.show("修改失败,找不到此盘点记录!","提 示",MessageBoxButtons.OK,MessageBoxIcon.Information)
    Return
Else
    dt = cmd1.ExecuteReader
    cmd1.CommandText = "Update {Zpandianbiao} Set [shenheren] = '" & shenheren & "' Where [danhao] = '" & danhao & "'"
End If

查询SQL数据表Zpandianbiao时,发现表中已有更新。
---------------------

代码2:
Dim cmd1 As New SQLCommand
Dim cmd2 As New SQLCommand
cmd1.C
cmd2.C
Dim dt As DataTable

Dim shenheren As String = "test"
Dim danhao As String = e.Form.Controls("danhao").value
Dim shipanshu As Integer
Dim shiyongren As String
Dim quyu As String
Dim diqu As String
Dim bianhao As String


If danhao = "" Then
    Messagebox.show("请输入盘点单号!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
    Return
End If

cmd1.CommandText = "Select * From {Zpandianbiao} Where danhao = '" & danhao & "' "
If cmd1.ExecuteScalar < 1 Then
    Messagebox.show("修改失败,找不到此盘点记录!","提 示",MessageBoxButtons.OK,MessageBoxIcon.Information)
    Return
Else
    dt = cmd1.ExecuteReader
    cmd1.CommandText = "Update {Zpandianbiao} Set [shenheren] = '" & shenheren & "' Where [danhao] = '" & danhao & "'"
End If

For Each dr As DataRow In dt.DataRows
    bianhao = dr("bianhao")
    shipanshu = dr("shipanshu")
    shiyongren = dr("shiyongren")
    quyu = dr("quyu")
    diqu = dr("diqu")
    cmd2.CommandText = "Update {Zzichanbiao} Set shuliang = " & shipanshu & ", shiy, quyu = '" & quyu & "', diqu = '" & diqu & "' Where bianhao = '" & bianhao & "'"
Next

If cmd2.ExecuteNonQuery > 0 Then '返回1表示更改成功
    Messagebox.show("审核成功!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
    Tables("盘点表_Table1").DataTable.Load()
    Vars("_AddEdit")=0
    e.Form.Controls("修改").Enabled = True
    e.Form.Controls("删除").Enabled = True
    e.Form.Controls("保存").Enabled = False
    e.Form.Controls("取消").Enabled = False
Else
    Messagebox.show("更改失败!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
End If

查询SQL数据表Zpandianbiao、Zzichanbiao时,发现两个表都没有更新。
---------------------
代码2:
Dim cmd1 As New SQLCommand
Dim cmd2 As New SQLCommand
cmd1.C
cmd2.C
Dim dt As DataTable

Dim shenheren As String = "test"
Dim danhao As String = e.Form.Controls("danhao").value
Dim shipanshu As Integer
Dim shiyongren As String
Dim quyu As String
Dim diqu As String
Dim bianhao As String


If danhao = "" Then
    Messagebox.show("请输入盘点单号!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
    Return
End If

cmd1.CommandText = "Select * From {Zpandianbiao} Where danhao = '" & danhao & "' "
If cmd1.ExecuteScalar < 1 Then
    Messagebox.show("修改失败,找不到此盘点记录!","提 示",MessageBoxButtons.OK,MessageBoxIcon.Information)
    Return
Else
    dt = cmd1.ExecuteReader
End If

For Each dr As DataRow In dt.DataRows
    bianhao = dr("bianhao")
    shipanshu = dr("shipanshu")
    shiyongren = dr("shiyongren")
    quyu = dr("quyu")
    diqu = dr("diqu")
    cmd1.CommandText = "Update {Zzichanbiao} Set shuliang = " & shipanshu & ", shiy, quyu = '" & quyu & "', diqu = '" & diqu & "' Where bianhao = '" & bianhao & "'"
Next

If cmd2.ExecuteNonQuery > 0 Then '返回1表示更改成功
    Messagebox.show("审核成功!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
    Tables("盘点表_Table1").DataTable.Load()
    Vars("_AddEdit")=0
    e.Form.Controls("修改").Enabled = True
    e.Form.Controls("删除").Enabled = True
    e.Form.Controls("保存").Enabled = False
    e.Form.Controls("取消").Enabled = False
Else
    Messagebox.show("更改失败!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
End If

查询SQL数据表Zzichanbiao时,发现符合条件的记录只有最后一个有更新。
---------------------

我希做到按下按键时,表Zpandianbiao的所有指定条件(单号为指定单号)的记录更新一下审核人信息,并在表Zzichanbiao中对应的记录中更新相应的多个字段。但目前无法做到表Zpandianbiao和表Zzichanbiao同时更新。



 回到顶部
美女呀,离线,留言给我吧!
danwenxie
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:婴狐 帖子:36 积分:419 威望:0 精华:0 注册:2013/11/25 11:08:00
  发帖心情 Post By:2014/8/21 11:00:00 [显示全部帖子]

所有代码段一开始的定义是:
Dim cmd1 As New SQLCommand
Dim cmd2 As New SQLCommand
cmd1.C——〉这里指定外部表
cmd2.C——〉这里指定外部表
Dim dt As DataTable

复制代码时不知道发现什么问题,选择不全,重新说明一下,
[此贴子已经被作者于2014-8-21 11:01:36编辑过]

 回到顶部
美女呀,离线,留言给我吧!
danwenxie
  3楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:婴狐 帖子:36 积分:419 威望:0 精华:0 注册:2013/11/25 11:08:00
  发帖心情 Post By:2014/8/21 11:03:00 [显示全部帖子]

谢谢您!我试试

 回到顶部
美女呀,离线,留言给我吧!
danwenxie
  4楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:婴狐 帖子:36 积分:419 威望:0 精华:0 注册:2013/11/25 11:08:00
  发帖心情 Post By:2014/8/21 11:06:00 [显示全部帖子]

谢谢有点甜大师,加上 cmd1.ExecuteNonQuery后好了。

 回到顶部