Library software in VB.net & SQL Server 2000

Well.., these days we know that programming are disposed to Object oriented programming like using Java and .Net applications like Visual Basic.Net. well, in this session, I try to make Library Application using Visual Basic.Net 2003 and SQL Server 2000, here we are :
1.Firstly, we have to make database in SQL server 2000, log on to your DBMS SQL server 2000
2.In the GUI of SQL Server, type : Created database Library, then press F5 or Execute
3.type script table :
create table Buku(
kdBuku varchar(7)primary key,
namaBuku varchar(35),
pengarang varchar(35),
penerbit varchar(30),
edisi varchar(5))
4.click execute

Now.., it’s time to make Book's form in Visual basic.Net. In GUI of Visual Basic.Net 2003, click file --> New --> Project :
1.Design form like a picture above
2.Now, on GUI of Visual basic.Net, click menu Tools --> connect to database --> then choose ‘Microsoft OLE Provider for SQL Server’, then click Next, then Fiil in the name of your SQL Server, choose ‘Use Windows NT Integrated Security’, click combobox for finding our database (Library), finally we can click button ‘Test Connection’, and click button OK.
3.well, Next we’d better set the properties, exactly for some components like textbox and button, for example textbox one is named by txtKode, textbox two is named by txtNama, etc.
4.Type the code bellow in Load Form :
dbPrp = New SqlClient.SqlConnection
dbPrp.ConnectionString = "Integrated Security=SSPI;Persist Security Info=False; Initial Catalog=Library;Data Source=Ader"
dbPrp.Open()
Note : don’t forget to change Data Source with your SQL Server’s name.
4.Type source code for btnSimpan for click event :
If dbPrp.State = ConnectionState.Closed Then dbPrp.Open()
com_buku = New SqlClient.SqlCommand
com_buku.CommandType = CommandType.Text
If lblEdit.Visible = False Then
com_buku.CommandText = "insert into buku values ('" & txtKode.Text & "','" & txtNama.Text & "','" _
& txtPengarang.Text & "','" & txtPenerbit.Text & "','" & txtEdisi.Text & "')"
Else
com_buku.CommandText = "update buku set namabuku = '" & txtNama.Text & "',pengarang = '" & txtPengarang.Text & "',penerbit = '" _
& txtPenerbit.Text & "',edisi = '" & txtEdisi.Text & "' where kdbuku = '" & txtKode.Text & "'"
End If
com_buku.Connection = dbPrp
com_buku.ExecuteNonQuery()
txtKode.Text = ""
txtNama.Text = ""
txtPengarang.Text = ""
txtPenerbit.Text = ""
txtEdisi.Text = ""
txtKode.Focus()
dbPrp.Close()
5.Type source code bellow for btnHapus for click event :
If dbPrp.State = ConnectionState.Closed Then dbPrp.Open()
com_buku = New SqlClient.SqlCommand
com_buku.CommandType = CommandType.Text
com_buku.CommandText = "delete from buku where kdbuku = '" & txtKode.Text & "'"
com_buku.Connection = dbPrp
com_buku.ExecuteNonQuery()
lblEdit.Visible = False
txtKode.Text = ""
txtNama.Text = ""
txtPengarang.Text = ""
txtPenerbit.Text = ""
txtEdisi.Text = ""
txtKode.Focus()
com_buku.Dispose()
dbPrp.Close()
6.Double click at txtKode, then change event click with lost_focus event, and type the code bellow :
If dbPrp.State = ConnectionState.Closed Then dbPrp.Open()
com_buku = New SqlClient.SqlCommand
com_buku.CommandType = CommandType.Text
com_buku.CommandText = "select * from buku where kdbuku = '" & txtKode.Text & "'"
com_buku.Connection = dbPrp
reader_buku = com_buku.ExecuteReader
If reader_buku.Read Then
txtNama.Text = reader_buku("namabuku")
txtPengarang.Text = reader_buku("pengarang")
txtPenerbit.Text = reader_buku("penerbit")
txtEdisi.Text = reader_buku("edisi")
lblEdit.Visible = True
Else
lblEdit.Visible = False
txtNama.Text = ""
txtPengarang.Text = ""
txtPenerbit.Text = ""
txtEdisi.Text = ""
End If
reader_buku.Close()
com_buku.Dispose()
dbPrp.Close()

Have a try it! Well.. we can also make this program in Visual Basic.Net 2005 or Visual Basic.Net 2008, or If you are interested for completely book of Visual Basic.Net programs, you can buy it the Book which gets title of “Pemrograman Visual Basic.Net 2005 dan Aplikasi Nyata dengan DBMS SQL Server 2005” Author Ade Rahmat and Yono Suryadi (Yrama widya; Publisher), get in Book Store of Gramedia :).

Created By Ader

Popular posts from this blog

Introduction to Use Case Diagram - Case study: Facebook

Sequential Search

Motivasi dan Semangat Menuntut Ilmu Agama Islam Sesuai Al-Qur’an dan Sunnah