以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  录入客户资料,禁止编号重复的问题  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=100927)

--  作者:zswushi
--  发布时间:2017/5/21 17:47:00
--  录入客户资料,禁止编号重复的问题
Dim cmd1 As New SQLCommand
    Dim cmd2 As New SQLCommand
    Dim Key As Integer
    cmd1.C \'设置数据源名称
    cmd2.C
    cmd1.commandText = "Select Count(*) F rom [单据编号] Where 单据前缀 = \'KHGL-\'"
messagebox.show("1")
    If cmd1.ExecuteScalar = 0 Then \'如果编号表不存在前缀的行,那么增加一行
        cmd1.commandtext = "In sert Into 单据编号 (单据前缀,顺序号) Values(\'KHGL-\',1)"
        cmd1.ExecuteNonQuery
    End If
    cmd1.commandText = "Select [顺序号] F rom [单据编号] Where 单据前缀 = \'KHGL-\'"
    Key = cmd1.ExecuteScalar() \'从后台获得顺序号
    cmd2.co mmandText = "Up date [单据编号] Set [顺序号] = " & (Key + 1) & " Where [顺序号] = " & Key & " And [单据前缀] = \'KHGL-\'"  

    If cmd2.ExecuteNonQuery() = 0 Then
        MessageBox.Show("客户编号重复!请重新输入!","提示")
        e.Form.Controls("textbox3").Select()
        Return 

    ElseIf cmd2.ExecuteNonQuery() > 0 Then \'更新顺序号
        Dim r As Row = Tables("客户管理").addnew()
        r("客户管理系统编号") = "KHGL-" & Format(Key,"00000")

单据编号的我已改好,怎么 客户、货品资料的去改的话,老是出错,提示  未将对象引用设置到 对象的实例??  谢谢


--  作者:有点蓝
--  发布时间:2017/5/22 8:46:00
--  
错误提示应该和这段代码没有关系。

datacolchanged事件代码看看。

另外这种编号处理建议加上事务,或者把这几条sql放到存储过程中统一调用,同样加上事务

--  作者:zswushi
--  发布时间:2017/5/22 16:47:00
--  
If e.Form.Controls("TextBox2").value = "" Then
    messagebox.show("客户编号不能为空","提示!")
    e.Form.Controls("textbox3").Select()
    Return
End If
If e.Form.Controls("增 加").Enabled = True Then
    Dim dr As DataRow
    If dr.RowState <> DataRowState.Added Then \'如果不是新增行
        Return \'那么返回
    End If
    Dim cmd1 As New SQLCommand
    Dim cmd2 As New SQLCommand
    Dim Key As Integer
    cmd1.C \'设置数据源名称
    cmd2.C
    cmd1.commandText = "Select Count(*) F rom [单据编号] Where 单据前缀 = \'KHGL-\'"
    If cmd1.ExecuteScalar = 0 Then \'如果编号表不存在前缀的行,那么增加一行
        cmd1.commandtext = "Ins ert Into 单据编号 (单据前缀,顺序号) Values(\'KHGL-\',1)"
        cmd1.ExecuteNonQuery
    End If
    cmd1.commandText = "Select [顺序号] F rom [单据编号] Where 单据前缀 = \'KHGL-\'"
    Key = cmd1.ExecuteScalar() \'从后台获得顺序号
    cmd2.commandText = "Up date [单据编号] Set [顺序号] = " & (Key + 1) & " Where [顺序号] = " & Key & " And [单据前缀] = \'KHGL-\'"  
    If cmd2.ExecuteNonQuery() = 0 Then
        MessageBox.Show("客户编号重复!请重新输入!","提示")
        e.Form.Controls("textbox3").Select()
        Return 
    Else
        Dim r As Row = Tables("客户管理").addnew()
  r("客户管理系统编号") = "KHGL-" & Format(Key,"00000")
              r("单据前缀")= e.Form.Controls("TextBox8").value
        r("客户编号")= e.Form.Controls("TextBox2").value
        r("客户名称")= e.Form.Controls("TextBox3").value
        r("内部编号")= e.Form.Controls("TextBox4").value
        r("联系人")= e.Form.Controls("TextBox5").value
        r("联系电话")= e.Form.Controls("TextBox6").value
        r("联系手机")= e.Form.Controls("TextBox7").value
        r("联系地址")= e.Form.Controls("TextBox12").value
        r("备注一")= e.Form.Controls("TextBox13").value
        r("客户类别")= e.Form.Controls("ComboBox1").value
        r("货运名称")= e.Form.Controls("ComboBox2").value
        r("结算方式")= e.Form.Controls("ComboBox3").value
        r("客户区域")= e.Form.Controls("ComboBox4").value
        Tables("客户管理").current.save()
        e.Form.Controls("TextBox2").value = ""
        e.Form.Controls("TextBox3").value = ""
        e.Form.Controls("TextBox4").value = ""
        e.Form.Controls("TextBox5").value = ""
        e.Form.Controls("TextBox6").value = ""
        e.Form.Controls("TextBox7").value = ""
        e.Form.Controls("TextBox8").value = ""
        e.Form.Controls("TextBox12").value = ""
        e.Form.Controls("TextBox13").value = ""
        e.Form.Controls("ComboBox1").value = ""
        e.Form.Controls("ComboBox2").value = ""
        e.Form.Controls("ComboBox3").value = ""
        e.Form.Controls("ComboBox4").value = ""
    End If
End If
这是完整的代码呀,就是提示 未将对象引用设置到对象的实例呀,我是用做保存按钮click ,事件呀



--  作者:有点色
--  发布时间:2017/5/22 17:02:00
--  

 在你的代码上,加入msgbox,定位一下出错位置。

 

 应该是你赋值的时候触发了datacolchanged等事件导致的吧?

[此贴子已经被作者于2017/5/22 17:02:17编辑过]

--  作者:zswushi
--  发布时间:2017/5/23 12:07:00
--  
问题基本解决,非常感谢!!