读书人

Adodc关于编辑选定的数据和判断重复数

发布时间: 2012-03-01 10:25:46 作者: rapoo

Adodc关于编辑选定的数据和判断重复数据 达人来
Adodc关于编辑选定的数据和判断重复数据 达人来

Adodc1.Recordset.ActiveConnection.Execute "Delete From data where 名称= ' " & CStr(MSHFlexGrid1.TextMatrix(MSHFlexGrid1.Row, 1)) & " ' " (名称, 单位) VALUES ( ' " & Text1(0).Text & " ' , ' " & Text1(1).Text & " ') "
怎么把上面这段代码改为修改选定的数据哦


Adodc1.Recordset.ActiveConnection.Execute "insert Into data(名称, 单位) VALUES ( ' " & Text1(0).Text & " ' , ' " & Text1(1).Text & " ') "
怎么在上面这段代码前判断重复的名称数据并msg哦


我不喜欢下面的语法哦,喜欢上面这种简洁的哦 ^^
Dim cn As New ADODB.Connection
Dim cm As New ADODB.Command
cn.Open

谢谢

[解决办法]
Adodc1.Recordset.ActiveConnection.Execute "Delete From data where 名称= ' " & CStr(MSHFlexGrid1.TextMatrix(MSHFlexGrid1.Row, 1)) & " ' " (名称, 单位) VALUES ( ' " & Text1(0).Text & " ' , ' " & Text1(1).Text & " ') "
怎么把上面这段代码改为修改选定的数据哦

Adodc1.Recordset.Delete

Adodc1.Recordset.ActiveConnection.Execute "insert Into data(名称, 单位) VALUES ( ' " & Text1(0).Text & " ' , ' " & Text1(1).Text & " ') "
怎么在上面这段代码前判断重复的名称数据并msg哦

方法1:
在 data 表中建一个唯一索引,包含 【名称】, 【单位】 字段。这样插入重复值将引发一个错误。用 On Error 语句拦截并处理错误就可以了。

方法2:
Adodc1.Recordset.DataSource = "Select * From data Where 名称= ' " & Text1(0) & " ' And 单位= ' " & Text1(1) & " ' "
Adodc1.Recordset.Refresh
If Adodc1.Recordset.EOF Then Adodc1.Recordset.ActiveConnection.Execute "insert Into data(名称, 单位) VALUES ( ' " & Text1(0).Text & " ' , ' " & Text1(1).Text & " ') "

读书人网 >VB

热点推荐