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)