sarigozoglu
Altın Üye
- Katılım
- 26 Eylül 2014
- Mesajlar
- 85
- Excel Vers. ve Dili
- Office 365 TR-32
DOSYA İndirmek/Yüklemek için ÜCRETLİ ALTIN ÜYELİK Gereklidir!
Altın Üyelik Hakkında Bilgi
'www.asriakdeniz.com - asriakdeniz@gmail.com 21.05.2016
Private CN As ADODB.Connection
Dim RS As ADODB.Recordset
Dim Field As ADODB.Field
Dim SQL As String
Dim Connected, hata As Boolean
Dim i, j, satis As Long
Dim yil, ay As Integer
Dim veri As String
Dim serverip, db, kullanici, sifre As String
Sub menu()
serverip = "127.0.0.1"
db = "TESTDB"
kullanici = "sa"
sifre = "123"
hata = False
Call karsilastir
If hata Then
MsgBox ("Server bağlantsı sağlanamadı.")
Else
MsgBox ("Insert ve Update işlemleri tamamlandı.")
End If
End Sub
Sub karsilastir()
Connected = Connect(serverip, db)
If Connected Then
Set RS = New ADODB.Recordset
Else
hata = True
Exit Sub
End If
sonsatir = Cells(Rows.Count, "A").End(3).Row
For j = 2 To sonsatir
yil = Cells(j, 2).Value
ay = Cells(j, 3).Value
satis = Cells(j, 4).Value
If yil = "" Then Exit For
veri = "T.YIL=" & yil & " AND T.AY=" & ay
SQL = "SELECT count(*) FROM TESTDB.DBO.TBLSATIS T WHERE " & veri
Set RS = CN.Execute(SQL)
If RS.Fields(0).Value <= 0 Then
veri = yil & "," & ay & "," & satis
SQL = "INSERT INTO TESTDB.DBO.TBLSATIS ([YIL],[AY],[SATIS]) VALUES(" & veri & ")"
If RS.State = adStateOpen Then RS.Close
RS.Open SQL, CN, adOpenStatic, adLockReadOnly, adCmdText
Else
veri = satis & " WHERE YIL=" & yil & " AND AY=" & ay
SQL = "UPDATE TESTDB.DBO.TBLSATIS SET SATIS=" & veri
Set RS = CN.Execute(SQL)
End If
Next
Set RS = Nothing
Call Disconnect
End Sub
Function Disconnect()
CN.Close
End Function
Function Connect(Server, database) As Boolean
Set CN = New ADODB.Connection
On Error Resume Next
With CN
.ConnectionString = "Provider=SQLOLEDB.1;" & _
"Persist Security Info=False;" & _
"Initial Catalog=" & database & ";" & _
"Data Source=" & Server & ";" & _
"User ID=" & kullanici & ";Password=" & sifre & ";"
.Open
End With
If CN.State = 0 Then
Connect = False
Else
Connect = True
End If
End Function
Çok teşekkür ederim Sn. Asri.
Gayet başarılı ve tam istediğim gibi çalışıyor. Bunun üzerinden devam edeceğim.
Tekrar ellerinize sağlık