Results 1 to 3 of 3
  1. #1
    Join Date
    Dec 2009

    Unanswered: Trying to link Visual Basic database app to Oracle database

    I'm creating a database application that will connect to Oracle. A textbox named txtFindByLastName and button named btnFindByLastName will search for a record in oracle that has the last name typed into the textbox. It keeps giving me an error. Can anyone see what I'm doing wrong? Visual Basic is telling me that it's having a problem with
    "Dim dr As OracleDataReader = cmd.ExecuteReader()".

    Private Sub btnFindByLastName_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFindByLastName.Click
    Dim XE As String = "Data Source=(DESCRIPTION=(ADDRESS_LIST=" _
    + "(ADDRESS=(PROTOCOL=TCP)(HOST=" + txtHost.Text + ")(PORT=1521)))" _
    + "User Id=system;Password=*******;"
    Dim conn As New OracleConnection(XE)


    Dim cmd As New OracleCommand

    cmd.Connection = conn
    cmd.CommandText = "SELECT Employee_ID, First_Name, Last_Name, EMail, Phone_Number, Hire_Date, Job_ID, Salary, Commission_Pct, Manager_ID, Department_ID FROM hr.Employees WHERE Last_Name = " + txtFindByLastName.Text
    cmd.CommandType = CommandType.Text

    Dim dr As OracleDataReader = cmd.ExecuteReader()
    txtEmployeeID.Text = dr.Item("Employee_ID").ToString
    txtFirstName.Text = dr.Item("First_Name").ToString
    txtLastName.Text = dr.Item("Last_Name").ToString
    txtEMail.Text = dr.Item("EMail").ToString
    txtPhoneNumber.Text = dr.Item("Phone_Number").ToString
    txtHireDate.Text = dr.Item("Hire_Date").ToString
    txtJobID.Text = dr.Item("Job_ID").ToString
    txtSalary.Text = dr.Item("Salary").ToString
    txtCommission.Text = dr.Item("Commission_Pct").ToString
    txtManagerID.Text = dr.Item("Manager_ID").ToString
    txtDepartmentID.Text = dr.Item("Department_ID").ToString
    txtFindByLastName.Text = ""

    End Sub
    Last edited by tiasholen; 12-08-09 at 08:41.

  2. #2
    Join Date
    Nov 2004
    out on a limb
    Provided Answers: 59
    it may help if you paste the error message and identify where the error is. its possible that someone who uses oracle as a back end db in VB could identify a fault without such information, but by not providing that information you are cutting down ther chances of you getting any useful help.

    it also would help you to specify whether you are using VB or VB.NET, and which version of VB or VB.NET

    on the face of it
    Build a .NET Application on the Oracle Database could be a good reference for you
    I'd rather be riding on the Tiger 800 or the Norton

  3. #3
    Join Date
    Dec 2009
    I believe that its because your CommandText string is incorrect - remember to put single quotes around your last name e.g.
    Last_Name = '" + txtFindByLastName.Text + "'"

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts