What's new

Closed The beginner's guide - vb.net ms sql ^_^

Status
Not open for further replies.

Acumen18

Addict
Joined
May 8, 2017
Posts
47
Reaction
21
Points
74
Try ko pa kayo turuan kung paano gamitin ang Vb.net 2010 at MS SQL 2008

Dapat may naka install ng VB.net sa Computer Nyo.
Link po para sa pag install ng SQL Server 2008: You do not have permission to view the full content of this post. Log in or register now.

Naka upload na po ang CRUDS
Create Read Update Search

Pa hit ng like naman wag yung puro download at tingin lang
 

Attachments

Last edited:
Beginner's Guide 01:paano gumawa ng Project sa vb.net 2010

Step 01:Click nyo lang yung New Project
upload_2017-7-11_13-37-32.png

Step 02: Dahil Windows Application ang gagawin naten Select nyo ang Windows Forms Application
Lagyan nyo yung System Name Gaya ng ipinapakita sa baba:upload_2017-7-11_13-40-59.png

Pag ka Click nyo ng Ok lalabas na itong page na ito na may default na Form1.vb
upload_2017-7-11_13-43-14.png

Step 03:Delete natin ngayon yang Form1.vb Kailangan Masanay kayo mag lagay ng tamang Pangalan sa mga Forms,fields at iba pa at para hindi kayo mahirapan sa pag hahanap.
Right Click Form1.vb Tapos Click nyo lang ang delete buttonupload_2017-7-11_13-50-11.png

Step 04:
Pag Create ng Form
Right Click nyo System Name ->Add->New Item

upload_2017-7-11_13-51-30.png

Pag ka Click nyo ng New Item Lalabas ang Window na ito

Ngayon Select nyo ang Windows Form Lagyan nyo ng Form Name gaya ng nasa baba tapos click nyo ang add button
upload_2017-7-11_13-54-25.png

Pag ka Click ng Add lalabas na ang window na ito
upload_2017-7-11_13-56-44.png
 

Attachments

Beginner's Guide 02:Pag gawa ng database para sa Employees Record na system

Step 01: Connect kayo sa MSSQL Server 2008 Express
Lagay nyo ang mga Credentials
Server Name
Authentication
Login
Password


Tapos Click nyo ang Connect

upload_2017-7-11_14-9-18.png


Pag ka Click nyo ng Connect Lalabas na ang windows na ito
upload_2017-7-11_14-20-25.png


Step 02:Right Click Databases Tapos New Database..

upload_2017-7-11_14-21-10.png

Pag Ka Click nyo ng New Database.. lalabas ng Windows na ito ngayon lagyan nyo na ng Database name:
Tapos Click OK
upload_2017-7-11_14-23-8.png

Ngayon Meron na kayong database Click Nyo yung Databases
Makikita nyo na ang ginawa nyong database
upload_2017-7-11_14-25-53.png

 

Attachments

Beginner's Guide 03:Pag gawa ng Table sa MSSQL Express 2008
Step 01:Right Click Tables Tapos Click nyo yung New Table

upload_2017-7-11_14-36-40.png

Pag ka Click Ng New Table lalabas itong Window na ito
upload_2017-7-11_14-40-52.png

Step 02:lalagyan na ng fields ang table.
mga fields na ilalagay:
Id Int (Autoincrement)
Firstname varchar(50)
Lastname varchar(50)
Middleinitial nchar(10)
IsActive Int(1)

!Important sa id na field kailangan naka yes ang (Is Identity) para mag auto Increment ang id
upload_2017-7-11_14-52-20.png

upload_2017-7-11_14-54-18.png
Pag ka lagay ng mga fields Click nyo yung save icon sa itaas Tapos lalabas ang windows alert Ilagay nto ang table name.

upload_2017-7-11_14-55-58.png


Pag ka Click ng Okay may table kana

upload_2017-7-11_14-57-55.png


Yan na lang muna next day ko na gagawin kung paano maka connect sa MSSQL ^_^
 

Attachments

Beginner's Guide 04:Connect to MS SQL Server 2008

Step 01:Right Click Project name tapos Click nyo yung Properties

upload_2017-7-11_15-43-36.png


Pag ka Click nyo ng Properties lalabas ang Window na ito

upload_2017-7-11_15-45-24.png

Step 02:Click nyo ang Settings
upload_2017-7-11_15-46-21.png

Step 03: Palitan nyo ang Name:Setting ng DBConnection At Type:Setting ng (Connection String) Scope:User ng Application
upload_2017-7-11_15-51-1.png


Step 04:Click nyo yun value

upload_2017-7-11_15-52-0.png

pag ka Click nyo nyan lalabas itong window na ito

upload_2017-7-11_15-52-53.png

Step 05:Lagay nyo na ng Credentials MS SQL SERVER 2008 nyo dyan

upload_2017-7-11_16-0-8.png
Tapos Click nyo Yung Test Connection Para Malaman nyo kung tama ang nagawa nyo


upload_2017-7-11_16-1-34.png

Yan Connected Kana sa Database
 

Attachments

Beginner's Guide 05:Retrieve Data to Datagridview

Step 01:Sa Employees.vb Dedesign na Form

upload_2017-7-12_11-1-21.png


Step 02:Create naman ng Stored Procedure para mag Retrieve na ng Data from Database to Datagridview
upload_2017-7-12_11-8-35.png

Tapos Copy paste new itong Query

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: Heizenberg
-- Create date: 07-12-2017
-- Description: Retrieve All Employees
-- =============================================
create PROCEDURE getemployees
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;

-- Insert statements for procedure here
SELECT id,
firstname as [FIRST NAME],
lastname as [LAST NAME],
middleinitial as [MIDDLE INITIAL],
CASE
WHEN isactive IS not null OR isactive = 1 THEN 'ACTIVE'
ELSE 'NOT ACTIVE'
END AS STATUS
from
tbl_employees
END
GO


Pag Ka Copy Paste nyo Click Nyo ang Execute
upload_2017-7-12_11-10-49.png

Pag ka Execute mo lalabas na Stored Procedure

upload_2017-7-12_11-12-40.png

Tapos ito Copy Paste Nyo Employee.vb

upload_2017-7-12_11-13-56.png


Imports System.Data
Imports System.Data.SqlClient
Public Class Employees
Public adp1 As SqlDataAdapter
Public ds As DataSet
Public TableName As String
Private Sub Employees_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Call load_employees()
End Sub
Sub load_employees()
Try
Dim SQLCon As SqlConnection
SQLCon = New SqlConnection(My.Settings.DBConnection)
If SQLCon.State = 1 Then SQLCon.Close()
SQLCon.Open()
Dim RetrieveEmployees As New SqlCommand
RetrieveEmployees.CommandText = "getemployees"
RetrieveEmployees.CommandType = CommandType.StoredProcedure
RetrieveEmployees.Connection = SQLCon
TableName = "tbl_employees"

ds = New DataSet()
adp1 = New SqlDataAdapter(RetrieveEmployees)
adp1.Fill(ds, TableName)

DataGridView2.DataSource = ds
DataGridView2.DataMember = TableName
DataGridView2.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.DisplayedCells
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Private Sub DataGridView2_SelectionChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGridView2.SelectionChanged
BindData(DataGridView2, txt_id, ck_isactive, txt_firstname, txt_lastname, txt_MI)
End Sub
Sub BindData(ByRef DataGridViewObj As DataGridView,
ByRef IdTextBox As TextBox,
ByRef ActiveCheckBox As CheckBox,
Optional ByVal Param1TextBox As TextBox = Nothing,
Optional ByVal Param2TextBox As TextBox = Nothing,
Optional ByVal Param3TextBox As TextBox = Nothing)
Try

With DataGridViewObj

If .CurrentRow.Cells(0).Value.ToString() = "" Then
IdTextBox.Text = ""
Else
IdTextBox.Text = .CurrentRow.Cells(0).Value.ToString()
End If

If .CurrentRow.Cells(1).Value.ToString() = "" Then
Param1TextBox.Text = ""
Else
Param1TextBox.Text = .CurrentRow.Cells(1).Value.ToString()
End If

If .CurrentRow.Cells(2).Value.ToString() = "" Then
Param2TextBox.Text = ""

Else
Param2TextBox.Text = .CurrentRow.Cells(2).Value.ToString()
End If

If .CurrentRow.Cells(3).Value.ToString() = "" Then
Param3TextBox.Text = ""

Else
Param3TextBox.Text = .CurrentRow.Cells(3).Value.ToString()
End If
If .CurrentRow.Cells(4).Value.ToString() = "ACTIVE" Then
ActiveCheckBox.Checked = 1

Else
ActiveCheckBox.Checked = 0
End If

End With

Catch ex As Exception

'MsgBox("Sorting")

End Try
End Sub


End Class


Yan na po ang magiging result
upload_2017-7-12_11-16-47.png
 

Attachments

Status
Not open for further replies.
Back
Top