Aşağıdaki kodlarla sqlden veri çekmeye çalışıyorum sql database bağlantısı kuramıyo Dim conn As New ADODB.Connection satırında hata veriyor.
Sub Module1
Public Sub banka()
Dim conn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim SqlText As String
With conn
.Provider = "sqloledb"
.CommandTimeout = 120
.ConnectionString = "Data Source=" & Sheet1.Cells(4, 5).Value & ";USER ID=" & Sheet1.Cells(8, 5).Value & ";PASSW=" & Sheet1.Cells(10, 5).Value & ";AUTO TRANSLATE=FALSE"
.Open
.DefaultDatabase = "" & Sheet1.Cells(6, 5).Value & ""
End With
SqlText = "SELECT A.KSMAS_KOD,B.KSMAS_NAME,"
SqlText = SqlText + " SUM((CASE WHEN A.IO='G' THEN A.TUTAR ELSE 0 END)-(CASE WHEN A.IO='C' THEN A.TUTAR ELSE 0 END))+SUM(B.KSSONDEV_T)"
SqlText = SqlText + " FROM TBLKASA A JOIN TBLKASAMAS B ON (A.KSMAS_KOD=B.KSMAS_KOD)"
SqlText = SqlText + " WHERE A.TARIH BETWEEN '" & Sheet9.Cells(5, 2).Value & "' AND '" & Sheet9.Cells(6, 2).Value & "' "
SqlText = SqlText + " GROUP BY A.KSMAS_KOD,B.KSMAS_NAME "
SqlText = SqlText + " ORDER BY A.KSMAS_KOD ASC"
rs.Open SqlText, conn, adOpenStatic, adLockReadOnly
Sheet9.Range("D4:F8").ClearContents
Sheet9.Activate
i = 4
Do While Not rs.EOF
Sheet9.Cells(i, 4).Value = rs(0)
Sheet9.Cells(i, 5).Value = rs(1)
Sheet9.Cells(i, 6).Value = rs(2)
rs.MoveNext
i = i + 1
Loop
rs.Close
conn.Close
Set rs = Nothing
Set conn = Nothing
End Sub
End Sub
Sub Module1
Public Sub banka()
Dim conn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim SqlText As String
With conn
.Provider = "sqloledb"
.CommandTimeout = 120
.ConnectionString = "Data Source=" & Sheet1.Cells(4, 5).Value & ";USER ID=" & Sheet1.Cells(8, 5).Value & ";PASSW=" & Sheet1.Cells(10, 5).Value & ";AUTO TRANSLATE=FALSE"
.Open
.DefaultDatabase = "" & Sheet1.Cells(6, 5).Value & ""
End With
SqlText = "SELECT A.KSMAS_KOD,B.KSMAS_NAME,"
SqlText = SqlText + " SUM((CASE WHEN A.IO='G' THEN A.TUTAR ELSE 0 END)-(CASE WHEN A.IO='C' THEN A.TUTAR ELSE 0 END))+SUM(B.KSSONDEV_T)"
SqlText = SqlText + " FROM TBLKASA A JOIN TBLKASAMAS B ON (A.KSMAS_KOD=B.KSMAS_KOD)"
SqlText = SqlText + " WHERE A.TARIH BETWEEN '" & Sheet9.Cells(5, 2).Value & "' AND '" & Sheet9.Cells(6, 2).Value & "' "
SqlText = SqlText + " GROUP BY A.KSMAS_KOD,B.KSMAS_NAME "
SqlText = SqlText + " ORDER BY A.KSMAS_KOD ASC"
rs.Open SqlText, conn, adOpenStatic, adLockReadOnly
Sheet9.Range("D4:F8").ClearContents
Sheet9.Activate
i = 4
Do While Not rs.EOF
Sheet9.Cells(i, 4).Value = rs(0)
Sheet9.Cells(i, 5).Value = rs(1)
Sheet9.Cells(i, 6).Value = rs(2)
rs.MoveNext
i = i + 1
Loop
rs.Close
conn.Close
Set rs = Nothing
Set conn = Nothing
End Sub
End Sub