One-to-Many or Master-Detail Data entry in Visual Basic .Net

0 comments

Posted on 4th December 2011 by Kenneth in Visual Basic .Net

, ,

Visual Basic .Net sample project on how to create a One-to-Many (Master-Detail) Data entry form using the Data Sources Window and the Windows Forms designer in Visual Studio. This project connect the database Order as the master or parent then retrieve the order details as the child. Get the source code here


 

Read Data from Oracle Database using Visual Basic .Net 2010

0 comments

Posted on 1st December 2011 by Admin in Visual Basic .Net |Visual Basic 2010

, ,

Sample code on how to access or retrieve data from Oracle database using visual basic .net 2010. Please add to reference the ODP.NET DLL to your visual studio reference in order to gain access to your oracle database server.

 

 

 

 


 

‘Sample Code Below

Imports Oracle.DataAccess.Client ‘ Visual Basic ODP.NET Oracle managed provider

Public Class frmdepartment

Private Sub frmdepartment_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim oradb As String = “Data Source=(DESCRIPTION=(ADDRESS_LIST=” _
+ “(ADDRESS=(PROTOCOL=TCP)(HOST=ORASRVR)(PORT=1521)))” _
+ “(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=ORCL)));” _
+ “User Id=hr;Password=hr;”

Dim conn As New OracleConnection(oradb) ‘ Visual Basic
conn.Open()

Dim cmd As New OracleCommand
cmd.Connection = conn
cmd.CommandText = “select department_id, department_name, location_id from departments” ‘ VB
cmd.CommandType = CommandType.Text

Dim dr As OracleDataReader = cmd.ExecuteReader()
While dr.Read()
ListBox1.Items.Add(“The ” + dr.Item(“department_name”) + _
” department is in ” + dr.Item(“location_id”).ToString())
End While

dr.Dispose()
cmd.Dispose()
conn.Dispose()
End Sub

End Class

Hotel Reservation System Sample Download using Visual Basic .Net

0 comments

Posted on 1st December 2011 by reyman in Visual Basic .Net |Visual Basic 2008

,


Hotel Reservation System using visual basic .net 2008 by Jomar P. This sample project include the basic feature of hotel reservation like guest reservation, billing system, change room, multiple account per room, guest report and other charges. Download project

Insert Record/Data that Contain Quotes in Visual Basic

0 comments

Posted on 9th July 2011 by Admin in Database Programming |Visual Basic .Net |Visual Basic 6

,

‘This visual basic shows how to use ADO to insert records into a database when fields contain quotes

‘The program creates a SQL INSERT statement. To protect against quotes in the
‘user-entered values, the program replaces each single quote with two single
‘quotes. The database replaces the pairs of quotes with single quotes when it
‘inserts the values. For example, the database treats the text “Tess’s Bakery” as
‘”Tess’s ” when it adds it to the database.

Private Sub cmdInsert_Click()
Dim DB_Name As String
Dim SQL_Str As String
Dim Conn As ADODB.Connection
Dim ctl As Control
‘ Get the data.
DB_Name = App.Path
If Right$(DB_Name, 1) <> “” Then DB_Name = DB_Name & “”
DB_Name = DB_Name & “Employee.mdb”
‘ Open a connection.
Set Conn = New ADODB.Connection
Conn.ConnectionString = “Provider=Microsoft.Jet.OLEDB.4.0;” & “Data Source=” & DB_Name & _
“;” & “Persist Security Info=False”
Conn.Open
‘ Compose the INSERT statement.
SQL_Str = “INSERT INTO Addresses “ & “(Name, Street, City, State, Zip) “ & ” VALUES (“ & _
“‘” & Replace$(txtName.Text, “‘”, “””) & “‘, “ & “‘” & _
Replace$(txtStreet.Text, “‘”, “””) & “‘, “ & “‘” & _
Replace$(txtCity.Text, “‘”, “””) & “‘, “ & “‘” & _
Replace$(txtState.Text, “‘”, “””) & “‘, “ & “‘” & _
Replace$(txtZip.Text, “‘”, “””) & “‘” & “)”
‘ Execute the statement.
Conn.Execute SQL_Str, , adCmdText
‘ Close the connection.
Conn.Close

‘ Clear the TextBoxes.

For Each ctl In Controls
If TypeOf ctl Is TextBox Then
ctl.Text = “”
End If
Next ctl

End Sub

Visual Basic ADO to Page Through Records 10 at a Time

0 comments

Posted on 7th July 2011 by Admin in Visual Basic .Net

, ,

Option Explicit

Private
m_CombinedNames As String
‘Display the first 10 records.

Private Sub cmdList_Click()
‘ Reset m_CombinedNames
‘ to select the first record.
m_CombinedNames = “,”
‘ Get the next 10 records.
cmdNext.Enabled = True
cmdNext_Click

End Sub

‘ Display the next 10 records.

Private Sub cmdNext_Click()
Dim DB_Name As String
Dim Conn As ADODB.Connection
Dim RS As ADODB.Recordset
Dim txt As String
Dim i As Integer
‘ Get the database name.

DB_Name = App.Path


If Right$(DB_Name, 1) <> “” Then DB_Name = DB_Name & “”
DB_Name = DB_Name & “Employee.mdb”
‘ Open a connection.
Set Conn = New ADODB.Connection
Conn.ConnectionString = “Provider=Microsoft.Jet.OLEDB.4.0;” & “Data Source=” & DB_Name & “;” & _
“Persist Security Info=False”
Conn.Open
‘ Get the next 10 records.

Set RS = Conn.Execute(“SELECT TOP 10 * FROM Employees “ & “WHERE LastName + ‘,’ + _
FirstName > “ & “‘” & m_CombinedNames & “‘ ORDER BY LastName, “ & “FirstName”)
‘ Display the records.
Do until RS.EOF
i = i + 1
txt = txt & vbCrLf & Format$(RS!EmployeeId, “@@@”) & ” “ & _
Format$(RS!LastName, “!@@@@@@@@@@@@@”) & Format$(RS!FirstName, “!@@@@@@@@@@@@@”)
m_CombinedNames = RS!LastName & “,” & RS!FirstName
RS.MoveNext
Loop
‘ See if we ran out of records.
If i < 10 Then
txt = txt & vbCrLf & “<END>”
cmdNext.Enabled = False
End If
‘ Display the data.
If Len(txt) > 0 Then txt = Mid$(txt, 3)
txtEmployees.Text = txt

End Sub