Site içi Arama
Veritabanındaki bilgileri belli kriterlere göre aratıp GridView nesnesinde gösterebilirisiniz. Bu örnekte Sql veritabanimizda kayitli olan bilgileri göstermeye çalıştık. Aşağıdaki şekillerden uygulamamızı görebilirsiniz.
Formunuza 1 adet textbox, 1 adet DropDownList,
1 adet Button, 1 adet GridView nesnesi ekleyin...Bahadirsa
Şekil 1
Şekil 2
Şekil 3
Şekil 4
Forma yazılacak kodlar:
Default.aspx.vb
Imports System.Data.Sql
Imports System.Data.SqlClient
Partial Class _Default
Inherits System.Web.UI.Page
Protected Sub btnAra_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnAra.Click
If txtAra.Text = "" Or dList.Text = "" Then
MsgBox("Text Kutusu Boş veya Kriter Seçmediniz...Bahadirsa", MsgBoxStyle.OkOnly, "Kayıt Arama Uyarı")
Exit Sub
End If
Select Case dList.SelectedIndex
Case 1
Dim baglan As Data.SqlClient.SqlConnection = New Data.SqlClient.SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\personel_kayit.mdf;Integrated Security=True;User Instance=True")
Dim adp As New Data.SqlClient.SqlDataAdapter
Dim str As String
str = "Select * From kayitlar Where Personel_ID =‘" & txtAra.Text & "‘"
adp.SelectCommand = New Data.SqlClient.SqlCommand(str, baglan)
Dim CB As Data.SqlClient.SqlCommandBuilder = New Data.SqlClient.SqlCommandBuilder(adp)
Dim cmd As New Data.SqlClient.SqlCommand(str, baglan)
baglan.Open()
Dim ds As New Data.DataSet
adp.Fill(ds)
GridView1.DataSource = ds.Tables(0)
GridView1.DataBind()
baglan.Close()
txtAra.Text = ""
Case 2
Dim baglan As Data.SqlClient.SqlConnection = New Data.SqlClient.SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\personel_kayit.mdf;Integrated Security=True;User Instance=True")
Dim adp As New Data.SqlClient.SqlDataAdapter
Dim str As String
str = "Select * From kayitlar Where Ad like ‘%" & txtAra.Text & "%‘"
adp.SelectCommand = New Data.SqlClient.SqlCommand(str, baglan)
Dim CB As Data.SqlClient.SqlCommandBuilder = New Data.SqlClient.SqlCommandBuilder(adp)
Dim cmd As New Data.SqlClient.SqlCommand(str, baglan)
baglan.Open()
Dim ds As New Data.DataSet
adp.Fill(ds)
GridView1.DataSource = ds.Tables(0)
GridView1.DataBind()
baglan.Close()
txtAra.Text = ""
Case 3
Dim baglan As Data.SqlClient.SqlConnection = New Data.SqlClient.SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\personel_kayit.mdf;Integrated Security=True;User Instance=True")
Dim adp As New Data.SqlClient.SqlDataAdapter
Dim str As String
str = "Select * From kayitlar Where Soyad like ‘%" & txtAra.Text & "%‘"
adp.SelectCommand = New Data.SqlClient.SqlCommand(str, baglan)
Dim CB As Data.SqlClient.SqlCommandBuilder = New Data.SqlClient.SqlCommandBuilder(adp)
Dim cmd As New Data.SqlClient.SqlCommand(str, baglan)
baglan.Open()
Dim ds As New Data.DataSet
adp.Fill(ds)
GridView1.DataSource = ds.Tables(0)
GridView1.DataBind()
baglan.Close()
txtAra.Text = ""
Case 4
Dim baglan As Data.SqlClient.SqlConnection = New Data.SqlClient.SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\personel_kayit.mdf;Integrated Security=True;User Instance=True")
Dim adp As New Data.SqlClient.SqlDataAdapter
Dim str As String
str = "Select * From kayitlar Where Kisim like ‘%" & txtAra.Text & "%‘"
adp.SelectCommand = New Data.SqlClient.SqlCommand(str, baglan)
Dim CB As Data.SqlClient.SqlCommandBuilder = New Data.SqlClient.SqlCommandBuilder(adp)
Dim cmd As New Data.SqlClient.SqlCommand(str, baglan)
baglan.Open()
Dim ds As New Data.DataSet
adp.Fill(ds)
GridView1.DataSource = ds.Tables(0)
GridView1.DataBind()
baglan.Close()
txtAra.Text = ""
Case 5
Dim baglan As Data.SqlClient.SqlConnection = New Data.SqlClient.SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\personel_kayit.mdf;Integrated Security=True;User Instance=True")
Dim adp As New Data.SqlClient.SqlDataAdapter
Dim str As String
str = "Select * From kayitlar "
adp.SelectCommand = New Data.SqlClient.SqlCommand(str, baglan)
Dim CB As Data.SqlClient.SqlCommandBuilder = New Data.SqlClient.SqlCommandBuilder(adp)
Dim cmd As New Data.SqlClient.SqlCommand(str, baglan)
baglan.Open()
Dim ds As New Data.DataSet
adp.Fill(ds)
GridView1.DataSource = ds.Tables(0)
GridView1.DataBind()
baglan.Close()
End Select
End Sub
Protected Sub dList_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles dList.SelectedIndexChanged
If dList.SelectedIndex = 5 Then
txtAra.Text = "Tümü Listeleniyor..."
End If
End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Session.Timeout = 1
End Sub
End Class
‘Makalenin Faydalı olması dileğiyle. Bir sonraki makalede görüşmek üzere...Bahadirsa