If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Visual Basic > Trying to link Visual Basic database app to Oracle database

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-07-09, 23:52
tiasholen tiasholen is offline
Registered User
 
Join Date: Dec 2009
Posts: 4
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)))" _
+ "(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=XE) ));" _
+ "User Id=system;Password=*******;"
Dim conn As New OracleConnection(XE)

conn.Open()

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()
dr.Read()
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 = ""

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

Last edited by tiasholen; 12-08-09 at 07:41.
Reply With Quote
  #2 (permalink)  
Old 12-08-09, 02:07
healdem healdem is offline
Jaded Developer
 
Join Date: Nov 2004
Location: out on a limb
Posts: 9,262
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 my Versys or my Tiger 800 let alone the Norton
Reply With Quote
  #3 (permalink)  
Old 12-09-09, 19:35
Ross_Pickard Ross_Pickard is offline
Registered User
 
Join Date: Dec 2009
Posts: 1
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 + "'"
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On