'database connection class file
'-------------------------------------------------------
Imports Oracle.DataAccess.Client
Imports System.Data
Public Class DataBaseConnection
Private con As New OracleConnection
ReadOnly Property connection() As OracleConnection
Get
Return con
End Get
End Property
Sub New()
con.ConnectionString = System.Configuration.ConfigurationManager.AppSettings("DBconnection")
con.Open()
End Sub
Sub closeConnection()
con.Close()
con.Dispose()
End Sub
End Class
'//////////////////////////////////////
'staff class file
'--------------------------------------
Imports Oracle.DataAccess
Imports System.Data
Imports System.Windows.Forms
Imports Oracle.DataAccess.Client
Public Class Staff
Dim tran As OracleTransaction
Private staffid As String
Private firstname As String
Private lastname As String
Private otherdetails As String
Property _staffid() As String
Get
Return staffid
End Get
Set(ByVal value As String)
staffid = value
End Set
End Property
Property _firstname() As String
Get
Return firstname
End Get
Set(ByVal value As String)
firstname = value
End Set
End Property
Property _lastname() As String
Get
Return lastname
End Get
Set(ByVal value As String)
lastname = value
End Set
End Property
Property _otherdetails() As String
Get
Return otherdetails
End Get
Set(ByVal value As String)
otherdetails = value
End Set
End Property
'staffid,firstname,lastname,otherdetails
Function RecordStaff() As Boolean
Dim cmd As New OracleCommand
Dim con As New DataBaseConnection
Dim returnVal As Integer = 0
Try
cmd.Connection = con.connection
cmd.CommandType = CommandType.StoredProcedure
cmd.CommandText = "insert_staff"
cmd.Parameters.Add("staffid", _staffid)
cmd.Parameters.Add("firstname", _firstname)
cmd.Parameters.Add("lastname", _lastname)
cmd.Parameters.Add("otherdetails", _otherdetails)
returnVal = cmd.ExecuteNonQuery
If returnVal > 0 Then
Return True
Else
Return False
End If
Catch e As Exception
'MsgBox("Invalid Field(s) or Staff Already EXIST.*Provide valid information")
Windows.Forms.MessageBox.Show("Invalid Field(s) or Staff Already EXIST.*Provide valid information.", _
"Critical Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Return False
Finally
'con.closeConnection()
cmd.Dispose()
'tran.Commit()
'tran.Rollback()
End Try
End Function
End Class
'////////////////////////////////////////////////
'app.config file
'-----------------------------------------
<?xml version="1.0" encoding="utf-8"?> <configuration> <appSettings> <add key="DBconnection" value="data source=xe;user id=kingwash;password=@kingwash" /> </appSettings> <connectionStrings> <!-- <add name="ConnectionString" connectionString="Data Source=xe;Persist Security Info=True;User ID=at123;Password=@123"
providerName="Oracle.DataAccess.Client" />--> </connectionStrings> </configuration>
///////////////////////////
'the back of the staff class form
'-----------------------------------------
Imports Oracle.DataAccess.Client
Public Class Form1
Dim STAFF As New Staff
' Private con As New OracleConnection
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
End Sub
'//This code here CAPITALIZED the first LETTER of word the user enters into the textbox
Public Function ProperCase(ByVal Text As String) As String
' Converts the passed chunk of text to "Proper Case"
Dim objCulture As New System.Globalization. _
CultureInfo("en-US")
Return objCulture.TextInfo.ToTitleCase(Text.ToLower)
End Function
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Dim dgrResult As Windows.Forms.DialogResult
Dim strMessage As String
strMessage = "Are you sure you want to save?"
dgrResult = Windows.Forms.MessageBox.Show(strMessage, _
"Save", Windows.Forms.MessageBoxButtons.YesNo, _
Windows.Forms.MessageBoxIcon.Question)
If dgrResult = Windows.Forms.DialogResult.Yes Then
STAFF._staffid = Me.TextBoxStaffId.Text.Trim
STAFF._firstname = Me.ProperCase(TextBoxFN.Text.Trim)
STAFF._lastname = Me.ProperCase(TextBoxLN.Text.Trim)
STAFF._otherdetails = Me.ProperCase(TextBoxOD.Text.Trim)
Else
'ClearFields()
'Response.Redirect("Staff.aspx")
End If
If STAFF.RecordStaff() Then
Windows.Forms.MessageBox.Show("RECORD SAVED")
Windows.Forms.MessageBox.Show("The record has been save successfully.", "Saving Record", MessageBoxButtons.OK, MessageBoxIcon.Information)
MessageBox.Show(Me.TextBoxFN.Text + " " + Me.TextBoxLN.Text, "Record created for ", MessageBoxButtons.OK)
' Windows.Forms.MessageBox.Show(Count & " people have been created.")
' ClearFields()
' Response.Redirect("Staff.aspx")
Else
Windows.Forms.MessageBox.Show("RECORD NOT SAVED")
Windows.Forms.MessageBox.Show("RECORD NOT SAVED.", "Error Saving", MessageBoxButtons.OK, MessageBoxIcon.Error)
Return
' ClearFields()
End If
End Sub
End Class
---------------------------
Please, i need help, i've spent weeks and sleepless night to solve this, but i can't
figure out how to solve it. Though i used the same connection file and app.config file
for my asp.net web.config and it works. I am using the same connection for a vb.net
application and it gives me error."OracleConnetion.ConnectionString" is in valid.
that is the error i get.
Please any help will be welcome.
Thanks in advance.
kingwash 0 Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.