10 Haziran 2013 Pazartesi
SQL İLE ÖRNEK ADRES DEFTERİ
KOD İNDİR
Form1
Imports System Imports System.Data Imports System.Data.SqlClient Public Class AnaFrm Dim BaglantiDATA As String = "Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|Abookdb.mdf;Integrated Security=True;User Instance=True" Dim sql, Durum As String Dim Baglan As SqlConnection Dim Komut As SqlCommand Dim SQLOku As SqlDataReader Private Sub ListeDoldur() isimListesi.Items.Clear() KartNoListesi.Items.Clear() Komut = New SqlCommand(sql, Baglan) Try Baglan.Open() SQLOku = Komut.ExecuteReader While SQLOku.Read KartNoListesi.Items.Add(SQLOku("cardNo")) isimListesi.Items.Add(SQLOku("fName")) End While Dim x As Integer = isimListesi.Items.Count lblCount.Text = "Kayıt Sayısı : " & x Catch ex As Exception LblMesaj.Text = "Data Okuma Hatası" Finally Baglan.Close() Call Clear() End Try Durum = "n" SilBtn.Enabled = False End Sub Private Sub DataDoldur() lblCardNo.Text = SQLOku("cardNo").ToString AdıTxt.Text = SQLOku("fName").ToString SoyadıTxt.Text = SQLOku("lName").ToString MeslekTxt.Text = SQLOku("nName").ToString MailTxt.Text = SQLOku("email").ToString AdresTxt.Text = SQLOku("address").ToString ŞehirTxt.Text = SQLOku("city").ToString EvTelNo.Text = SQLOku("hphone").ToString CepTelNo.Text = SQLOku("mphone").ToString İşTelNo.Text = SQLOku("wphone").ToString End Sub Private Sub Clear() lblCardNo.Text = "" AdıTxt.Clear() SoyadıTxt.Clear() MeslekTxt.Clear() MailTxt.Clear() AdresTxt.Clear() ŞehirTxt.Clear() EvTelNo.Clear() CepTelNo.Clear() İşTelNo.Clear() 'txtfName.Focus() End Sub Private Sub Anafrm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Baglan = New SqlConnection(BaglantiDATA) sql = "SELECT * FROM contacts ORDER BY fName" Call ListeDoldur() End Sub Private Sub isimListesi_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles isimListesi.SelectedIndexChanged KartNoListesi.SelectedIndex = isimListesi.SelectedIndex Dim Kart As String = KartNoListesi.SelectedItem sql = "SELECT * FROM contacts WHERE cardNo='" + CStr(Kart) + "' ORDER BY fName" Komut = New SqlCommand(sql, Baglan) Try Baglan.Open() SQLOku = Komut.ExecuteReader While SQLOku.Read Call DataDoldur() End While Catch ex As Exception LblMesaj.Text = "Data Okuma Hatası" Finally Baglan.Close() End Try Durum = "u" SilBtn.Enabled = True End Sub Private Sub BulTxt_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BulTxt.TextChanged Dim find As String = BulTxt.Text sql = "SELECT * FROM contacts WHERE fName LIKE '" + CStr(find) + "%' ORDER BY fName" Call ListeDoldur() End Sub Private Sub SaklaBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaklaBtn.Click Select Case Durum Case "n" If AdıTxt.Text = "" Then LblMesaj.Text = "İsim boş olamaz" Else Try Baglan.Open() Dim Ekle As String = "INSERT INTO contacts VALUES('" & AdıTxt.Text & "','" & SoyadıTxt.Text & "','" & MeslekTxt.Text & "','" & _ MailTxt.Text & "','" & AdresTxt.Text & "','" & ŞehirTxt.Text & "','" & EvTelNo.Text & "','" & CepTelNo.Text & "','" & İşTelNo.Text & "')" Komut = New SqlCommand(Ekle, Baglan) Komut.ExecuteNonQuery() LblMesaj.Text = "Kayıt Saklandı" Catch ex As Exception LblMesaj.Text = "Kayıt Saklama Hatası" Finally Baglan.Close() End Try End If Case "u" If AdıTxt.Text = "" Then LblMesaj.Text = "İsim boş olamaz" Else Try Baglan.Open() Dim Güncelle As String = "UPDATE contacts SET fName='" & AdıTxt.Text & "',lName='" & SoyadıTxt.Text & "',nName='" & MeslekTxt.Text & "',email='" & MailTxt.Text & "',address='" & _ AdresTxt.Text & "',city='" & ŞehirTxt.Text & "',hphone='" & EvTelNo.Text & "',mphone='" & CepTelNo.Text & "',wphone='" & İşTelNo.Text & "' WHERE cardNo=" & lblCardNo.Text Komut = New SqlCommand(Güncelle, Baglan) Komut.ExecuteNonQuery() LblMesaj.Text = "Kayıt Güncellendi" Catch ex As Exception LblMesaj.Text = "Kayıt Güncelleme Hatası" Finally Baglan.Close() End Try End If End Select sql = "SELECT * FROM contacts ORDER BY fName" Call ListeDoldur() BulTxt.Clear() AdıTxt.Focus() End Sub Private Sub YeniBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles YeniBtn.Click Call Clear() AdıTxt.Focus() Durum = "n" SilBtn.Enabled = False End Sub Private Sub SilBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SilBtn.Click Dim Msj As DialogResult Msj = MessageBox.Show("Sil " + AdıTxt.Text & " " & SoyadıTxt.Text + " ?", "kayıt Sil", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) If Msj = Windows.Forms.DialogResult.Yes Then Try Baglan.Open() Dim Sil As String = "DELETE FROM contacts WHERE cardNo='" & lblCardNo.Text & "'" Komut = New SqlCommand(Sil, Baglan) Komut.ExecuteNonQuery() Catch ex As Exception LblMesaj.Text = "Kayıt Silme hatası" Finally Baglan.Close() End Try sql = "SELECT * FROM contacts ORDER BY fName" Call ListeDoldur() BulTxt.Clear() AdıTxt.Focus() End If End Sub Private Sub KapatBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles KapatBtn.Click Application.Exit() End Sub Private Sub HkkBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles HkkBtn.Click HkkFrm.Top = Me.Top HkkFrm.Left = Me.Left + Me.Width - HkkFrm.Width HkkFrm.Show() End Sub Private Sub AdıTxt_Click(sender As System.Object, e As System.EventArgs) Handles AdıTxt.Click, MyBase.Click, isimListesi.Click, LblMesaj.Click LblMesaj.Text = "" End Sub Private Sub LblMesaj_MouseMove(sender As System.Object, e As System.Windows.Forms.MouseEventArgs) Handles LblMesaj.MouseMove LblMesaj.Text = "" End Sub End Class
Form2
Imports System.Net.Mail Public Class HkkFrm Private Sub HkkFrm_Deactivate(sender As Object, e As System.EventArgs) Handles Me.Deactivate Me.Hide() End Sub Private Sub HkkFrm_FormClosed(sender As Object, e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed Me.Hide() End Sub Private Sub HkkFrm_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load 'Me.Height = 235 On Error Resume Next Dim ApplicationTitle As String If My.Application.Info.Title <> "" Then ApplicationTitle = My.Application.Info.Title Else ApplicationTitle = System.IO.Path.GetFileNameWithoutExtension(My.Application.Info.AssemblyName) End If Me.Text = ApplicationTitle & " Hakkında" 'String.Format(ApplicationTitle, " Hakkında {0}") Me.LabelProductName.Text = My.Application.Info.ProductName Me.LabelVersion.Text = String.Format("Version {0}", My.Application.Info.Version.ToString) Me.LabelCopyright.Text = My.Application.Info.Copyright Me.LabelCompanyName.Text = My.Application.Info.CompanyName 'Me.TextBox1.Text = My.Application.Info.Description LinkLabel1.Text = "http://eraslancemil.blogspot.com/" LinkLabel1.Links.Add(0, LinkLabel1.Text.Length, "http://eraslancemil.blogspot.com/") End Sub Private Sub LinkLabel1_LinkClicked(sender As System.Object, e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles LinkLabel1.LinkClicked If My.Computer.Network.IsAvailable = False Then 'MessageBox.Show("Bilgisayarınız İnternete Bağlı Değil.") Anafrm.LblMesaj.Text = "İnternet Bağlantısı Yok" Exit Sub End If System.Diagnostics.Process.Start(e.Link.LinkData) End Sub Private Sub Label2_Click(sender As System.Object, e As System.EventArgs) Handles Label2.Click If My.Computer.Network.IsAvailable = False Then 'MessageBox.Show("Bilgisayarınız İnternete Bağlı Değil.") AnaFrm.LblMesaj.Text = "İnternet Bağlantısı Yok" Exit Sub End If 'eraslancemil@gmail.com System.Diagnostics.Process.Start("mailto:eraslancemil@gmail.com") End Sub Private Sub Label2_MouseMove(sender As System.Object, e As System.Windows.Forms.MouseEventArgs) Handles Label2.MouseMove Windows.Forms.Cursor.Current = Cursors.Hand End Sub End Class
Sonraki Kayıt
Önceki Kayıt
Ana Sayfa