ÖRNEK – 1
NOT: SINAVDA BENZER BİR PROGRAM SORULACAKTIR.
KAYIT PROCEDURE’ Ü VE KAYIT PROGRAMI
YAZILACAKTIR. AYRICA KAYITLAR LISTVIEW İÇERİSİNDE
LİSTELENECEKTİR.
MODÜL
Module Module1
Public resim As String
Public baglanti As New
SqlClient.SqlConnection("Server=ILKERUNAL\ILKERUNAL;Database=kitap;User
Id='sa';Password='1'")
Public komut As New SqlClient.SqlCommand
Public adaptor As New SqlClient.SqlDataAdapter
Public ds As New DataSet
Public id As Integer
End Module
PROCEDUR
Create proc kitap_getir
@kitap_id as bigint
as
begin
select kitap.kitap_ad,yazar.yazar_ad,tur.tur_ad,kitap.kitap_fiyat
from kitap,yazar,tur
where kitap.yazar_id=yazar.yazar_id and kitap.tur_id=tur.tur_id and
[email protected]_id
end
Create Proc kitap_kayit
@kitap_ad as varchar(50),
@yazar_ad as varchar(50),
@kitap_tur as varchar(50),
@kitap_fiyat as money,
@kitap_resim as varchar(255),
@kitap_id as bigint output
AS
BEGIN
declare @tur_id as bigint
declare @yazar_id as bigint
declare @say as bigint
select @say=count(*) from tur where [email protected]_tur
if @say<=0
begin
insert into tur(tur_ad) values(@kitap_tur)
select @tur_id=tur_id from tur where [email protected]_tur
end
else
begin
select @tur_id=tur_id from tur where [email protected]_tur
end
select @say=count(*) from yazar where [email protected]_ad
if @say<=0
begin
insert into yazar(yazar_ad) values(@yazar_ad)
select @yazar_id=yazar_id from yazar where [email protected]_ad
end
else
begin
select @yazar_id=yazar_id from yazar where [email protected]_ad
end
select @say=count(*) from kitap where [email protected]_ad
if @say<=0
begin
insert into kitap(kitap_ad,yazar_id,tur_id,kitap_fiyat,kitap_resim)
values(@kitap_ad,@yazar_id,@tur_id,@kitap_fiyat,@kitap_resim)
select @kitap_id=@@identity from kitap
end
END
PROGRAM
Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles PictureBox1.Click
OpenFileDialog1.ShowDialog()
resim = OpenFileDialog1.FileName
PictureBox1.Image = Image.FromFile(resim)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
komut.Connection = baglanti
komut.CommandType = CommandType.StoredProcedure
komut.CommandText = "kitap_kayit"
baglanti.Open()
komut.Parameters.Add(New SqlClient.SqlParameter("@kitap_ad",
SqlDbType.VarChar)).Value = TextBox1.Text
komut.Parameters.Add(New SqlClient.SqlParameter("@yazar_ad",
SqlDbType.VarChar)).Value = ComboBox1.Text
komut.Parameters.Add(New SqlClient.SqlParameter("@kitap_tur",
SqlDbType.VarChar)).Value = ComboBox2.Text
komut.Parameters.Add(New SqlClient.SqlParameter("@kitap_fiyat",
SqlDbType.Money)).Value = TextBox2.Text
komut.Parameters.Add(New SqlClient.SqlParameter("@kitap_resim",
SqlDbType.VarChar)).Value = resim
komut.Parameters.Add(New SqlClient.SqlParameter("@kitap_id",
SqlDbType.BigInt)).Direction = ParameterDirection.Output
komut.ExecuteNonQuery()
baglanti.Close()
id = komut.Parameters("@kitap_id").Value
komut.Parameters.Clear()
Call goster()
End Sub
Public Sub goster()
Dim say As Integer = 0
ımageList1.Images.Clear()
ListView1.Items.Clear()
komut.Connection = baglanti
komut.CommandType = CommandType.Text
komut.CommandText = "Select * from kitap"
baglanti.Open()
Dim oku As SqlClient.SqlDataReader
oku = komut.ExecuteReader
While (oku.Read = True)
ımageList1.Images.Add(Image.FromFile(oku(5).ToString))
ListView1.Items.Add(oku(0) & "-" & oku(1), say)
say = say + 1
End While
baglanti.Close()
End Sub
Private Sub ListView1_SelectedIndexChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
ListView1.SelectedIndexChanged
Dim parca() As String
If ListView1.Items.Count > 0 Then
For Each item As ListViewItem In ListView1.SelectedItems
parca = item.Text.Split("-")
id = parca(0)
Next
End If
komut.Connection = baglanti
komut.CommandType = CommandType.StoredProcedure
komut.CommandText = "kitap_getir"
komut.Parameters.Add(New SqlClient.SqlParameter("@kitap_id",
SqlDbType.BigInt)).Value = id
baglanti.Open()
adaptor = New SqlClient.SqlDataAdapter(komut)
ds.Clear()
adaptor.Fill(ds)
DataGridView1.DataSource = ds.Tables(0)
baglanti.Close()
komut.Parameters.Clear()
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Call goster()
End Sub
NOT: SINAVDA KAYIT PROCEDURE’ Ü VE KAYIT
PROGRAMI YAZILACAKTIR. AYRICA KAYITLAR LISTVIEW
İÇERİSİNDE LİSTELENECEKTİR.
Download

vize_ornekleri