编程论坛
400万+工程师在用
华为|鸿蒙开发者日
直播报名
400万+工程师在用
华为|鸿蒙开发者日
直播报名

电子发烧友网工程师

17年用户 16436经验值
擅长:可编程逻辑 MEMS/传感技术 测量仪表 模拟技术 控制/MCU RF/无线
私信 关注

CursorType、LockType 和 EditMode 属性范例 (VB)

2009-1-8 10:19

<p><font face="Verdana">CursorType、LockType 和 EditMode 属性范例 (VB)</font></p><font face="Verdana">
<p><br/>本范例演示在打开 Recordset 前设置 CursorType 和 LockType 属性,还显示不同情况下 EditMode 属性的值。运行此过程需要 EditModeOutput 函数。</p>
<p>Public Sub EditModeX()</p>
<p>&nbsp;&nbsp;&nbsp; Dim cnn1 As ADODB.Connection<br/>&nbsp;&nbsp;&nbsp; Dim rstEmployees As ADODB.Recordset<br/>&nbsp;&nbsp;&nbsp; Dim strCnn As String</p>
<p>&nbsp;&nbsp;&nbsp; ' Open recordset with data from Employee table.<br/>&nbsp;&nbsp;&nbsp; Set cnn1 = New ADODB.Connection<br/>&nbsp;&nbsp;&nbsp; strCnn = "Provider=sqloLEDb;" &amp; _<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "Data Source=srv;Initial Catalog=Pubs;User Id=sa;Password=; "<br/>&nbsp;&nbsp;&nbsp; cnn1.Open strCnn<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; Set rstEmployees = New ADODB.Recordset<br/>&nbsp;&nbsp;&nbsp; Set rstEmployees.ActiveConnection = cnn1<br/>&nbsp;&nbsp;&nbsp; rstEmployees.CursorLocation = adUseClient<br/>&nbsp;&nbsp;&nbsp; rstEmployees.CursorType = adOpenStatic<br/>&nbsp;&nbsp;&nbsp; rstEmployees.LockType = adLockBatchOptimistic<br/>&nbsp;&nbsp;&nbsp; rstEmployees.Open "employee", , , , adCmdTable</p>
<p>&nbsp;&nbsp;&nbsp; ' Show the EditMode property under dIFferent editing<br/>&nbsp;&nbsp;&nbsp; ' states.<br/>&nbsp;&nbsp;&nbsp; rstEmployees.AddNew<br/>&nbsp;&nbsp;&nbsp; rstEmployees!emp_id = "T-T55555M"<br/>&nbsp;&nbsp;&nbsp; rstEmployees!fname = "temp_fname"<br/>&nbsp;&nbsp;&nbsp; rstEmployees!lname = "temp_lname"<br/>&nbsp;&nbsp;&nbsp; EditModeOutput "After AddNew:", rstEmployees.EditMode<br/>&nbsp;&nbsp;&nbsp; rstEmployees.UpdateBatch<br/>&nbsp;&nbsp;&nbsp; EditModeOutput "After UpdateBatch:", rstEmployees.EditMode<br/>&nbsp;&nbsp;&nbsp; rstEmployees!fname = "test"<br/>&nbsp;&nbsp;&nbsp; EditModeOutput "After Edit:", rstEmployees.EditMode<br/>&nbsp;&nbsp;&nbsp; rstEmployees.Close<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; ' Delete new record because this is a demonstration.<br/>&nbsp;&nbsp;&nbsp; cnn1.Execute "DELETE FROM employee WHERE emp_id = 'T-T55555M'"</p>
<p>End Sub</p>
<p>Public Function EditModeOutput(strTemp As String, _<br/>&nbsp;&nbsp;&nbsp; intEditMode As Integer)</p>
<p>&nbsp;&nbsp;&nbsp; ' Print report based on the value of the EditMode <br/>&nbsp;&nbsp;&nbsp; ' property.<br/>&nbsp;&nbsp;&nbsp; debug.Print strTemp<br/>&nbsp;&nbsp;&nbsp; Debug.Print "&nbsp; EditMode = ";</p>
<p>&nbsp;&nbsp;&nbsp; Select Case intEditMode<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Case adEditNone<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Debug.Print "adEditNone"<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Case adEditInProgress<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Debug.Print "adEditInProgress"<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Case adEditAdd<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Debug.Print "adEditAdd"<br/>&nbsp;&nbsp;&nbsp; End Select</p>
<p>End Function</p>
<p></font>&nbsp;</p>

更多回帖

打开APP