在对记录添加时,如何判断新输入的TEXT1(绑定MDB库的表的编号字段)的内容与库中原有的编号字段内容不重复.请详细指教.多谢.
解决方案 »
- upload file using http and asp.net(continue)????
- VB读文本文件出现的怪事,求解惑
- 1个关于DATAGRID控件和SQL2000连接的简单问题高分求解~~~~~
- 如何用ADODC1执行SQL语句?
- 设定好了datagrid与数据库的绑定,也设定了datagrid以及数据集的refresh和update属性,可就是更改不了数据库,如何解决,在线等待!!急
- excel编完程后,要多次使用该excel的问题
- 请教在VB编译环境下和生成Exe文件后的奇怪问题
- 如何制作控件?
- 谁有ASP的帮助资料呢?最好是微软出版的chm版的。感谢!
- vbz中调用DOS下文件的问题。急
- MSHFlexGrid控件怎么可以不显示第一行和第一列?即只显示数据?
- 在VB6里怎么取到word中的一个textBox里的text值?
if rs.eof then
添加
else
不添加
endif
if not rs.eof then
msgbox "编号已经存在,请重新输入!",vbinformation,"提示窗口"
text1.setfocus
exit sub
endif
On Error GoTo errorHandlerDim adoCnn As ADODB.Connection
Dim adoRst As ADODB.Recordset
Dim BeginTransBol As Boolean '是否已开始一个 ado 事务
Dim CnnStr As String
Dim cSql As StringBeginTransBol = False
CnnRst = "provider=Microsoft.Jet.OLEDB.4.0;Data source =" + [Access97、Access2000 数据库路径及名称] + " ;Persist Security Info=False;Jet OLEDB:Database Password=" + [数据库密码]
With adoCnn
If .State = adStateOpen Then .Close
.ConnectionString = CnnStr
.Open
If .State = adStateOpen Then
' 数据库打开成功
' 开始一个事物,设置事务的隔离层为 adXactReadCommitted .IsolationLevel = adXactReadUncommitted ' adXactReadCommitted
.BeginTrans
BeginTransBol = True
cSql = "SELECT * FROM 表 WHERE 编号 = " + Text1.Text
With adoRst
If .State = adStateOpen Then .Close
.ActiveConnection = adoCnn
.CursorLocation = adUseClient
.LockType = adLockBatchOptimistic
.CursorType = adOpenStatic
.Source = cSql
.Open
' Disconnect the recordset 切断记录集
Set .ActiveConnection = Nothing
If .RecordCount <> 0 Then
MsgBox "编号已经存在,请重新输入!", vbInformation, "录入重复窗口 . . ."
Text1.SetFocus
Else
.AddNew
'开始添加记录
.Fields("编号").Value = Text1.Text
'...
' Reconnect and update Access or SQL Server
.ActiveConnection = adoCnn
.UpdateBatch
End If
End With
.CommitTrans
BeginTransBol = False
Else
' 数据库打开失败
' ...
End If
End With
Exit Sub
errorHandler:
If adoCnn.State = adStateOpen And BeginTransBol Then adoCnn.RollbackTrans
MsgBox Err.Description + "(错误号:" + CStr(Err.Number) + ")", vbCritical, "出错拉 . . ."
End Sub