怎么通过VB访问SQL Server数据库
的有关信息介绍如下:要连接SQL数据库有两种方法用ADODC或ADO.方法一: (ADODC)首先须引用Projects-Components-Microsoft ADO Data Controls 6.0 (OLEDB).之后在表单设置ADODC控件。然后Form_Load()输入以下代码:Private Sub Form_Load()ADODC1.ConnectionString = "Provider=SQLOLEDB;Password=密码;Persist Security Info=False;User ID=用户名;Initial Catalog=数据库名;Data Source=服务器名" ADODC1.CommandType = adCmdTextADODC1.RecordSource = "select * from 表格名称"ADODC1.RefreshEnd Sub方法二: (ADO)'首先须引用Projects-References-Microsoft Active X Data Objects 2.0 Library.'*注意以下两段须写在程式最上面(Gerenal一般)中。Dim cn As New ADODB.ConnectionDim rs As New ADODB.RecordsetDim SQL As String'然后在Form_Load()输入以下代码:Private Sub Form_Load()cn.ConnectionString = "Provider=SQLOLEDB;Password=密码;Persist Security Info=False;User ID=用户名;Initial Catalog=数据库名;Data Source=服务器名" cn.OpenIf rs.State = adStateOpen Then rs.Closers.CursorLocation = adUseClientSQL = "select * from 表格名"rs.Open Trim$(SQL), cn, adOpenKeyset, adLockPessimisticEnd Sub