Tablodan Veri Okuma
Bu örneğimizde oluşturacağımız tablodan veri okuyacağız.
Şekil 1
Şekil 2
Forma yazılacak kodlar:
Imports System
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnVeriAl.Click
With Me.DataGridView1.RowTemplate
.DefaultCellStyle.BackColor = Color.LightYellow
.DefaultCellStyle.ForeColor = Color.Navy
.DefaultCellStyle.Font = New Font("Verdana", 10, FontStyle.Regular)
End With
Dim columnHeaderStyle As New DataGridViewCellStyle
columnHeaderStyle.BackColor = Color.Aqua
columnHeaderStyle.ForeColor = Color.AliceBlue
columnHeaderStyle.Font = New Font("Verdana", 10, FontStyle.Bold)
DataGridView1.ColumnHeadersDefaultCellStyle = columnHeaderStyle
DataGridView1.GridColor = Color.Black
Dim Table1 As DataTable
Table1 = New DataTable("Customers")
Dim str1 As String() = {"Bahadirsa", "xxxxx", "Muhendis", "Master", "Istanbul"}
Dim str2 As String() = {"Fatih", "Koç", "Muhendis", "Üniversite", "Istanbul"}
Dim str3 As String() = {"Haluk", "Akman", "Muhendis", "Üniversite", "Istanbul"}
Dim str4 As String() = {"Ahmet", "Aydın", "Muhendis", "Üniversite", "Istanbul"}
Dim str5 As String() = {"Kürşat", "Şahin", "Muhendis", "Üniversite", "Istanbul"}
Try
Dim ad As DataColumn = New DataColumn("Ad")
ad.DataType = System.Type.GetType("System.String")
Table1.Columns.Add(ad)
Dim soyad As DataColumn = New DataColumn("Soyad")
soyad.DataType = System.Type.GetType("System.String")
Table1.Columns.Add(soyad)
Dim meslek As DataColumn = New DataColumn("Meslek")
meslek.DataType = System.Type.GetType("System.String")
Table1.Columns.Add(meslek)
Dim ogrenim As DataColumn = New DataColumn("Öğrenim")
ogrenim.DataType = System.Type.GetType("System.String")
Table1.Columns.Add(ogrenim)
Dim il As DataColumn = New DataColumn("İl")
il.DataType = System.Type.GetType("System.String")
Table1.Columns.Add(il)
With Table1.Rows
.Add(str1)
.Add(str2)
.Add(str3)
.Add(str4)
.Add(str5)
End With
Catch
End Try
Dim ds As New Data.DataSet()
ds = New Data.DataSet()
ds.Tables.Add(Table1)
DataGridView1.DataSource = ds.Tables(0)
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
With Me
.Text = "Tablodan DataGridView a Veri Alma...Bahadirsa"
.MaximizeBox = False
.Location = New Point(200, 200)
End With
End Sub
End Class
‘Bir sonraki makalede buluşmak dileğiyle...Bahadirsa