dim FindName as String FindName=txtFind.text dim rsFind as adodb.recordset ADO数据的连接 …… if rsfind.eof then msgbox "对不起数据库中无此物资" exit sub else 加载数据 end if
If Adodc1.Recordset.RecordCount > 0 And IsNull(text1.Text) = False Then Adodc1.Recordset.MoveFirst Adodc1.Recordset.Find “GSM手机号码='" & text1.Text & "'"
这是我写的程序,我运行的时候不正确,妳帮我看一下 Private Sub search_data() If datPrimaryRS.Recordset.RecordCount > 0 And IsNull(txtFields(10).Text) = False Then datPrimaryRS.Recordset.MoveFirst datPrimaryRS.Recordset.Find (GSM手机号码 = "ingsmnumber") End If
If datPrimaryRS.Recordset.EOF = True Then MsgBox "新客户信息,注意" datPrimaryRS.Recordset.AddNew datPrimaryRS.Recordset.Fields("GSM手机号码") = ingsmnumber datPrimaryRS.Recordset.Fields("短消息内容") = inword & "--" & Time & "--" & Date & vbCrLf datPrimaryRS.Recordset.Update Else MsgBox "老客户信息"
datPrimaryRS.Recordset.Fields("短消息内容") = inword & "--" & Time & "--" & Date & vbCrLf datPrimaryRS.Recordset.Update
End IfEnd Sub因为我不知道该如何使用find来查询,ingsmnumber是手机号码.inword是短消息内容,我运行程序是,告诉我 datPrimaryRS.Recordset.Find (GSM手机号码 = "ingsmnumber")里的ingsmnuber使用的不正确 我怎么能保证,如果这个手机号码存在,我能将短消息内容存在这个手机号码的同一个纪录里
Dim sHM As String'存放手机号变量 Adodc1.Refresh With Adodc1.Recordset .MoveFirst .Find "GSM手机号='" & sHM & "'" If Not .EOF Then MsgBox "找到!" Else MsgBox "没有此记录!" End If End With
首先要确定你的数据库表中有这个字段,然后用更新语句就行了 比如: update 表名 set 字段名=字段值 where ....
我试了,我接收的是同一个手机的同一条信息,可是没次它不能把短消息存在同一个字段里 这是我的程序If datPrimaryRS.Recordset.RecordCount > 0 And IsNull(txtFields(10).Text) = False Then datPrimaryRS.Refresh If Not datPrimaryRS.Recordset.EOF Then datPrimaryRS.Recordset.MoveFirst datPrimaryRS.Recordset.Find "GSM手机号码= '" & ingsmnumber & "'" If datPrimaryRS.Recordset.EOF = True Then MsgBox "新客户信息,注意" datPrimaryRS.Recordset.AddNew datPrimaryRS.Recordset.Fields("GSM手机号码") = ingsmnumber datPrimaryRS.Recordset.Fields("短消息内容") = inword & "--" & Time & "--" & Date & vbCrLfElse MsgBox "老客户信息,请查阅"
datPrimaryRS.Recordset.Fields("短消息内容") = inword & "--" & Time & "--" & Date & vbCrLf datPrimaryRS.Recordset.Update
FindName=txtFind.text
dim rsFind as adodb.recordset
ADO数据的连接
……
if rsfind.eof then
msgbox "对不起数据库中无此物资"
exit sub
else
加载数据
end if
Adodc1.Recordset.MoveFirst
Adodc1.Recordset.Find “GSM手机号码='" & text1.Text & "'"
End If
Private Sub search_data() If datPrimaryRS.Recordset.RecordCount > 0 And IsNull(txtFields(10).Text) = False Then
datPrimaryRS.Recordset.MoveFirst
datPrimaryRS.Recordset.Find (GSM手机号码 = "ingsmnumber")
End If
If datPrimaryRS.Recordset.EOF = True Then
MsgBox "新客户信息,注意"
datPrimaryRS.Recordset.AddNew
datPrimaryRS.Recordset.Fields("GSM手机号码") = ingsmnumber
datPrimaryRS.Recordset.Fields("短消息内容") = inword & "--" & Time & "--" & Date & vbCrLf
datPrimaryRS.Recordset.Update
Else
MsgBox "老客户信息"
datPrimaryRS.Recordset.Fields("短消息内容") = inword & "--" & Time & "--" & Date & vbCrLf
datPrimaryRS.Recordset.Update
End IfEnd Sub因为我不知道该如何使用find来查询,ingsmnumber是手机号码.inword是短消息内容,我运行程序是,告诉我 datPrimaryRS.Recordset.Find (GSM手机号码 = "ingsmnumber")里的ingsmnuber使用的不正确
我怎么能保证,如果这个手机号码存在,我能将短消息内容存在这个手机号码的同一个纪录里
想用么
把表结构告诉
我帮你写SQL语句
谢谢
.Find "GSM手机号码='" & "ingsmnumber" & "'" !!! "ingsmnumber"就是呢要查找的字符串,可以用变量代替。
.Find (GSM手机号码 = "ingsmnumber") 你这么写怎么能对呢?好好看看find方法的语法吧
能帮我解决吗?
谢谢
Adodc1.Refresh
With Adodc1.Recordset
.MoveFirst
.Find "GSM手机号='" & sHM & "'"
If Not .EOF Then
MsgBox "找到!"
Else
MsgBox "没有此记录!"
End If
End With
比如:
update 表名 set 字段名=字段值 where ....
这是我的程序If datPrimaryRS.Recordset.RecordCount > 0 And IsNull(txtFields(10).Text) = False Then
datPrimaryRS.Refresh
If Not datPrimaryRS.Recordset.EOF Then datPrimaryRS.Recordset.MoveFirst
datPrimaryRS.Recordset.Find "GSM手机号码= '" & ingsmnumber & "'"
If datPrimaryRS.Recordset.EOF = True Then
MsgBox "新客户信息,注意"
datPrimaryRS.Recordset.AddNew
datPrimaryRS.Recordset.Fields("GSM手机号码") = ingsmnumber
datPrimaryRS.Recordset.Fields("短消息内容") = inword & "--" & Time & "--" & Date & vbCrLfElse
MsgBox "老客户信息,请查阅"
datPrimaryRS.Recordset.Fields("短消息内容") = inword & "--" & Time & "--" & Date & vbCrLf
datPrimaryRS.Recordset.Update
End IfEnd If
其次,如果确实能够找到,而又无法修改它,那么
就用这样一个办法来实现它,先把它彻底删除掉,
然后再新添上,
我想这样在UPDATE后,应该就可以实现你的目的了
我现在是怀疑你的FIND函数是否能够正确找到你所要的记录
你自己调试一下看是否正确
还有你是通过什么来控件显示数据库里的短消息内容的呢?
谢谢!!
MsgBox "新客户信息,注意"
datPrimaryRS.Recordset.AddNew
datPrimaryRS.Recordset.Fields("GSM手机号码") = ingsmnumber
datPrimaryRS.Recordset.Fields("短消息内容") = inword & "--" & Time & "--" & Date & vbCrLfElse
MsgBox "老客户信息,请查阅"
datPrimaryRS.Recordset.Fields("短消息内容") = datPrimaryRS.Recordset.Fields("短消息内容") & inword & "--" & Time & "--" & Date & vbCrLf
datPrimaryRS.Recordset.Update
End If思路是找到老客户后将他原来的短消息与新短消息做字符串连接,然后更新记录。
这样就行了!