Başlangıç > Kodlar > Visual Basic 6 ile Sql server 2000’e bağlantı yapıp rapor alma

Visual Basic 6 ile Sql server 2000’e bağlantı yapıp rapor alma


Bu program parçacığı ile sql server 2000 üzerinde tutulan bir veritabanına erişim sağlar.

Private Sub Command1_Click() ‘kayıt arama
On Local Error GoTo hata
cmd1.CommandText = “select *from bolum where bolno=” & Text1.Text
Set rs1 = cmd1.Execute
Text2 = rs1.Fields(“boladi”)
Adodc1.CommandType = adCmdText
Adodc1.RecordSource = “select *from bolum where bolno=” & Text1.Text
Adodc1.Refresh
DataGrid1.Refresh
DataGrid1.Visible = True
hata:
Select Case Err.Number
Case 3021
MsgBox “BÖYLE BİR KAYIT YOK”
End Select

End Sub

Private Sub degistir_Click() ‘değiştirme
baglan.Execute “update bolum set boladi='” & Text2.Text & “‘ where bolno=” & Text1.Text
Adodc1.Refresh
End Sub

Private Sub Form_Load()
AccessConnect = “Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=firma;Data Source=MKCSERVER”
Set baglan = New ADODB.Connection
baglan.ConnectionString = AccessConnect
baglan.Open

Set cmd1 = New ADODB.Command
cmd1.ActiveConnection = baglan
Set cmd2 = New ADODB.Command
cmd2.ActiveConnection = baglan
End Sub

Private Sub kayit_Click() ‘bilgi ekleme
On Local Error GoTo hata
baglan.Execute “INSERT INTO bolum(bolno,boladi) values (” & Text1.Text & “,'” & Text2.Text & “‘)”

hata:
Select Case Err.Number
Case 0
MsgBox “KAYIT BAŞARI İLE YAPILDI”
End Select
End Sub

Private Sub sil_Click() ‘sil
baglan.Execute “delete bolum where bolno=” & Text1.Text & “”
Adodc1.Refresh
End Sub

Private Sub temizle_Click()
Text1 = “”
Text2 = “”

End Sub

rapor isimli bir başka forma altına yazılacaklar
önce dataenviroment nesnesi ile bağlantı yapılacak ve data report oluşturulmalıdır

Private Sub göster_Click()
Adodc1.CommandType = adCmdText
If Option1.Value = True Then
Adodc1.RecordSource = “select maas,ad,soyad from personel order by maas desc”
Else
Adodc1.RecordSource = “select maas,ad,soyad from personel order by maas asc”
End If

Adodc1.Refresh
End Sub

Private Sub rapor_Click()’rapora kriteri gönderip raporu aç
DataEnvironment1.rsCommand1.Open
DataEnvironment1.Commands(1).CommandType = adCmdText
If Option1.Value = True Then
DataEnvironment1.Commands(1).CommandText = “select maas,ad,soyad from personel order by maas desc”
Else
DataEnvironment1.Commands(1).CommandText = “select maas,ad,soyad from personel order by maas asc”
End If
DataEnvironment1.Commands(1).Execute
DataEnvironment1.rsCommand1.Requery
DataReport2.Show
End Sub


TD Software


  1. Henüz yorum yapılmamış.
  1. No trackbacks yet.

Yorum bırakın