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

电子发烧友网工程师

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

Provider 和 DefaultDatabase 属性范例 (VB)

2009-1-8 10:24

<p><font face="Verdana">Provider 和 DefaultDatabase 属性范例 (VB)</font></p><font face="Verdana">
<p><br/>本范例通过打开三个使用不同提供者的 Connection 对象来演示 Provider 属性。它还使用 DefaultDatabase 属性来设置 microsoft ODBC Provider 的默认数据库。</p>
<p>Public Sub ProviderX()</p>
<p>&nbsp;&nbsp;&nbsp; Dim cnn1 As ADODB.Connection<br/>&nbsp;&nbsp;&nbsp; Dim cnn2 As ADODB.Connection<br/>&nbsp;&nbsp;&nbsp; Dim cnn3 As ADODB.Connection</p>
<p>&nbsp;&nbsp;&nbsp; ' Open a connection using the Microsoft ODBC provider.<br/>&nbsp;&nbsp;&nbsp; Set cnn1 = New ADODB.Connection<br/>&nbsp;&nbsp;&nbsp; cnn1.C &amp; _<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "server=srv;uid=sa;pwd=pwd"<br/>&nbsp;&nbsp;&nbsp; cnn1.Open strCnn<br/>&nbsp;&nbsp;&nbsp; cnn1.DefaultDatabase = "Pubs"<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; ' display the provider.<br/>&nbsp;&nbsp;&nbsp; MsgBox "Cnn1 provider: " &amp; cnn1.Provider</p>
<p>&nbsp;&nbsp;&nbsp; ' Open a connection using the Microsoft Jet provider.<br/>&nbsp;&nbsp;&nbsp; Set cnn2 = New ADODB.Connection<br/>&nbsp;&nbsp;&nbsp; cnn2.Provider = "Microsoft.Jet.OLEDB.3.51"<br/>&nbsp;&nbsp;&nbsp; cnn2.Open "C:\Samples\northwind.mdb", "admin", ""</p>
<p>&nbsp;&nbsp;&nbsp; ' Display the provider.<br/>&nbsp;&nbsp;&nbsp; MsgBox "Cnn2 provider: " &amp; cnn2.Provider</p>
<p>&nbsp;&nbsp; ' Open a connection using the Microsoft SQL Server provider.<br/>&nbsp;&nbsp;&nbsp; Set cnn3 = New ADODB.Connection<br/>&nbsp;&nbsp;&nbsp; cnn3.Provider = "sqloledb"<br/>&nbsp;&nbsp;&nbsp; cnn3.Open "Data Source=srv;Initial Catalog=Pubs;", "sa", ""</p>
<p>&nbsp;&nbsp;&nbsp; ' Display the provider.<br/>&nbsp;&nbsp;&nbsp; MsgBox "Cnn3 provider: " &amp; cnn3.Provider</p>
<p>&nbsp;&nbsp;&nbsp; cnn1.Close<br/>&nbsp;&nbsp;&nbsp; cnn2.Close<br/>&nbsp;&nbsp;&nbsp; cnn3.Close</p>
<p>End Sub</p>
<p></font>&nbsp;</p>

更多回帖

打开APP