vb中refresh方法执行之后,对Recordset.RecordCount属性会产生什么影响

来源:百度知道 编辑:UC知道 时间:2024/05/28 19:37:57
恳请高手指点
SqlString = "Select * From Company where 公司名称='" + txtName.Text + "'"
Adodc3.ConnectionString = ADODCstr
Adodc3.RecordSource = SqlString
Adodc3.Refresh
If isAdd Then
If Adodc3.Recordset.RecordCount > 0 Then
MsgBox "该公司名已存在!"
SaveInformation = False
Exit Function
为什么通过判断Adodc3.Recordset.RecordCount 是否大于零就能知道有重名的呢?

因为Select * From Company where 公司名称='" + txtName.Text + "'"
会取出所有数据库中“公司名称”与文本框中输入的内容相同的记录,>0表示存在这样的记录。如果再添加的话,当然会重名了