读书人

小弟我的程序为何不是小弟我想要的结果

发布时间: 2012-01-21 21:31:43 作者: rapoo

我的程序为何不是我想要的结果
我用了一个消费表,在form中做了几个textbox,分别是单据编号、会员卡号、会员姓名、商品名称等,通过绑定与表建立关系,TEXTBOX的内容是表的字段,输入的时候提示相关信息,但不知道为什么在运行的时候,“单据编号不能为空”总不提示,但“会员卡号不能为空”等都提示,各位大虾帮帮忙!
代码为:
Private Function storeconsume() As Boolean

Dim str As String
Dim m_listno1, m_vipid, m_goods, m_vipname, m_number, m_unitprice, m_sumprice, m_consumedate, m_integral, m_discount As String
Dim operatetype As Integer
Dim StrCnn As New ADODB.Connection
Dim rs As New ADODB.Recordset


storeconsume = False

If Textdjbh.Text = " " Then ——〉就是这里不运行,其余都能出现提示
MsgBox "单据编号不能为空! "
Textdjbh.SetFocus
Exit Function
Else
m_listno1 = Textdjbh.Text
End If


If Text1.Text = " " Then
MsgBox "会员卡号不能为空! "
Text1.SetFocus
Exit Function
Else
m_vipid = Text1.Text
End If
If Text2.Text = " " Then
MsgBox "会员姓名不能为空! "
Text2.SetFocus
Exit Function
Else
m_vipname = Text2.Text
End If
If Textgoodsname.Text = " " Then
MsgBox "商品名称不能为空! "
Textgoodsname.SetFocus
Exit Function
Else
m_goods = Textgoodsname.Text
End If
If Textdanjia.Text = " " Then
MsgBox "单价不能为空! "
Textdanjia.SetFocus
Exit Function
Else
m_unitprice = Textdanjia.Text
End If
If Textnumber.Text = " " Then
MsgBox "数量不能为空! "
Textnumber.SetFocus
Exit Function
Else
m_number = Textnumber.Text
End If
If DTxf.Value = " " Then
MsgBox "消费日期不能为空! "
DTxf.SetFocus


Exit Function
Else
m_consumedate = DTxf.Value
End If
Set rs = Adodc3.Recordset
Set StrCnn = New ADODB.Connection
If operatetype = 1 Then '判断输入的单据编号在consume表中是否存在。
Set rs = StrCnn.Execute( "select * from consume where listno1= ' " & Textdjbh.Text & " ' ")
Else
If operatetype = 2 Then
Set rs = StrCnn.Execute( "select * from consume where listno1= ' " & Textdjbh.Text & " ' ")

End If
End If

If Not rs.EOF Then
MsgBox "单据编号已经存在! "
Textdjbh.SetFocus
Exit Function
End If


If operatetype = 1 Then '判断输入的会员卡号在consume表中是否存在
Set rs = StrCnn.Execute( "select * from consume where vipid= ' " & Text1.Text & " ' ")
Else
If operatetype = 2 Then
Set rs = StrCnn.Execute( "select * from consume where vipid= ' " & Text1.Text & " ' ")
End If
End If
If Not rs.EOF Then
MsgBox "会员卡号已经存在! "
Text1.SetFocus
Exit Function
End If

If operatetype = 1 Then '存储新消费纪录到consume表
str = "insert into consume(listno1,vipid,goods,vipname,number,unitprice,sumprice,consumedate,integral,discount) values( ' " & m_listno1 & " ' , ' " & m_vipid & " ', ' " & m_goods & " ', ' " & m_vipname & " ', ' " & m_number & " ', ' " & m_unitprice & " ', ' " & m_sumprice & " ', ' " & m_consumedate & " ', ' " & m_integral & " ', ' " & m_discount & " ') "


StrCnn.Execute (str)
Else
If operatetype = 2 Then
Set rs = StrCnn.Execute( "select * from consume where vipid= ' " & Text1.Text & " ' ")
StrCnn.Execute (str)
End If
End If
storeconsume = True
Exit Function
End Function
到底是哪里有问题?

[解决办法]
这样试试:
If trim(Textdjbh.Text) = " " Then
[解决办法]
哦感觉也是需要trim(...)
[解决办法]
这样试试
if Textdjbh.Text& " "= " " Then
[解决办法]
If operatetype = 1 or operatetype=2 Then '判断输入的单据编号在consume表中是否存在。
if rs.state <> adstateclosed then rs.close
rs.open "select * from consume where listno1= ' "& trim(textdjbh.text) & " ' " ",strcnn,adopenkeyset,adlockreadonly
if rs.recordcount> 0 then
MsgBox "单据编号已经存在! "
rs.close
Textdjbh.SetFocus
Exit Function
End If

[解决办法]
operatetype是否进行了赋值
[解决办法]
...................................
[解决办法]
strcnn与数据库建立关联了吗
[解决办法]
' " & m_discount & " ', ' "& m_person1& " '中的逗号改为英文状态下的逗号试试

读书人网 >VB

热点推荐