连接数据库方面,该如何处理
连接数据库方面
说用户名'sa'登录失败。该用户与可信SQL Server连接无关联。
说用户名'sa'登录失败。该用户与可信SQL Server连接无关联。
Public conn As New ADODB.Connection '公用数据库连接
Dim xlapp As New Excel.Application
Public Sub main()
'打开数据连接字符串
'打开窗体frmain和frmlogin
conn.Open "Provider=SQLOLEDB.1;Password=zjtj;Persist Security Info=True;User ID=sa;Initial Catalog=CSJXC;Data Source=."
frmLogin.Show
End Sub
Public Function SetSql(strSql As String) As String
'定义不带返回的数据连接
Dim cmd As New ADODB.Command
On Error Resume Next
Set cmd.ActiveConnection = conn
cmd.CommandText = strSql
cmd.Execute
If Err Then
Exec_SqL = Err.Description
Exit Function
End If
On Error GoTo 0
SetSql = "OK"
End Function
Public Function GetSql(strSql As String) As ADODB.Recordset
'定义带返回记录级的数据连接
Dim rs As New ADODB.Recordset
With rs
.CursorLocation = adUseClient
If .State = 1 Then .Close
.Open strSql, conn, adOpenDynamic, adLockOptimistic
End With
Set GetSql = rs
End Function
Public Sub UpdateDDD(ddd As MSHFlexGrid, rs As ADODB.Recordset)
'以数据库记录集中地记录更新相应的显示列表
With rs
If .RecordCount > 0 Then
Dim i As Long
Dim ii As Long
If .RecordCount > 30 Then
ddd.Rows = .RecordCount + 1
End If
i = 1
Do Until .EOF
For ii = 0 To ddd.Cols - 1
ddd.TextMatrix(i, ii) = " " & Trim(.Fields(ii).Value)
Next
.MoveNext
i = i + 1
Loop
End If
End With
End Sub
Function ReturnText(strText As String, intLen As Long)
If Len(strText) > intLen Then
ReturnText = Mid(strText, 1, intLen) & "..."
Else
ReturnText = strText
End If
End Function
Function MoveFont(ddd As MSHFlexGrid, intRow As Long)
'当选中列表中的某行时,该列高亮度显示(如果改变行时,还原刚才的行为正常显示)
Dim i As Long
Dim ii As Long
For i = 1 To ddd.Rows - 1
If i <> intRow Then
ddd.Col = 0
ddd.Row = i