Click here to Skip to main content
12,634,888 members (28,821 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: VB VB.NET
Hello. I have the following simple database:


CREATE TABLE MiamiIslandResorts (
ID number(2),
ResortName varchar2(30),
ResortRating varchar2(15),
Primary Key(ID));

insert into MiamiIslandResorts (id, ResortName, ResortRating) values (1, 'Palm Springs Resorts', '5 stars');
insert into MiamiIslandResorts (id, ResortName, ResortRating) values (2, 'Beaches Resorts', '3 stars');
insert into MiamiIslandResorts (id, ResortName, ResortRating) values (3, 'Sands Resorts', '5 stars');
insert into MiamiIslandResorts (id, ResortName, ResortRating) values (4, 'Islands Resorts', '4 stars');
insert into MiamiIslandResorts (id, ResortName, ResortRating) values (5, 'Diamond Resorts', '5 stars');
insert into MiamiIslandResorts (id, ResortName, ResortRating) values (6, 'Tropical Springs Resorts', '4 stars');
insert into MiamiIslandResorts (id, ResortName, ResortRating) values (7, 'Island Paridise Resorts', '3 stars');
insert into MiamiIslandResorts (id, ResortName, ResortRating) values (8, 'Paridise Resorts', '5 stars');



Create Table RentalCarAgencies(
ID number(2),
Agency varchar2(25),
AgencyRating varchar2(15),
Primary Key(ID));

insert into RentalCarAgencies (ID, Agency, AgencyRating) values (1, 'Avis', '4 stars');
insert into RentalCarAgencies (ID, Agency, AgencyRating) values (2, 'Enterprise', '4 stars');
insert into RentalCarAgencies (ID, Agency, AgencyRating) values (3, 'Budget', '4 stars');
insert into RentalCarAgencies (ID, Agency, AgencyRating) values (4, 'Dollar', '2 stars');
insert into RentalCarAgencies (ID, Agency, AgencyRating) values (5, 'Hertz', '5 stars');


Create Table RentalCarTypes(
ID number(2),
CarType varchar2(20),
Primary Key(ID));

insert into RentalCarTypes (ID, CarType) values (1, 'Economy');
insert into RentalCarTypes (ID, CarType) values (2, 'Compact');
insert into RentalCarTypes (ID, CarType) values (3, 'Midsize Sedan');
insert into RentalCarTypes (ID, CarType) values (4, 'Large Sedan');
insert into RentalCarTypes (ID, CarType) values (5, 'SUV');
insert into RentalCarTypes (ID, CarType) values (6, 'Pickup Truck');
insert into RentalCarTypes (ID, CarType) values (7, 'Mini Van');
insert into RentalCarTypes (ID, CarType) values (8, '12 Passanger van');
insert into RentalCarTypes (ID, CarType) values (9, 'Economy');


Create Table Month(
ID number(2),
Month varchar2(25),
Primary Key (ID));

insert into Month (ID, MONTH) values (1, 'January');
insert into Month (ID, MONTH) values (2, 'February');
insert into Month (ID, MONTH) values (3, 'March');
insert into Month (ID, MONTH) values (4, 'April');
insert into Month (ID, MONTH) values (5, 'May');
insert into Month (ID, MONTH) values (6, 'June');
insert into Month (ID, MONTH) values (7, 'July');
insert into Month (ID, MONTH) values (8, 'August');
insert into Month (ID, MONTH) values (9, 'September');
insert into Month (ID, MONTH) values (10, 'October');
insert into Month (ID, MONTH) values (11, 'November');
insert into Month (ID, MONTH) values (12, 'December');


CREATE TABLE TypeOfView (
ID number(2),
ViewType varchar2(20),
Primary Key(ID));

insert into TypeofView (ID, ViewType) values (1, 'Ocean View');
insert into TypeofView (ID, ViewType) values (2, 'Interior View');
insert into TypeofView (ID, ViewType) values (3, 'Balcony View');
insert into TypeofView (ID, ViewType) values (4, 'Penthouse View');


CREATE TABLE ReasonForStay (
ID number(2),
StayType varchar2(25),
Primary Key (ID));

insert into ReasonForStay (ID, StayType) values (1, 'Business');
insert into ReasonForStay (ID, StayType) values (2, 'Personal');
insert into ReasonForStay (ID, StayType) values (3, 'Vacation');
insert into ReasonForStay (ID, StayType) values (4, 'Wedding');
insert into ReasonForStay (ID, StayType) values (5, 'Anniversary');
insert into ReasonForStay (ID, StayType) values (6, 'Reunion');



CREATE TABLE NumberOfGuests (
Id number(2),
TotalNumber varchar2(20),
Primary Key(ID));

insert into NumberOfGuests (ID, TotalNumber) values (1, '1');
insert into NumberOfGuests (ID, TotalNumber) values (2, '2');
insert into NumberOfGuests (ID, TotalNumber) values (3, '3');
insert into NumberOfGuests (ID, TotalNumber) values (4, '4');
insert into NumberOfGuests (ID, TotalNumber) values (5, '5');
insert into NumberOfGuests (ID, TotalNumber) values (6, '6');
insert into NumberOfGuests (ID, TotalNumber) values (7, '7');
insert into NumberOfGuests (ID, TotalNumber) values (8, '8');
insert into NumberOfGuests (ID, TotalNumber) values (9, '9');
insert into NumberOfGuests (ID, TotalNumber) values (10, '10');
insert into NumberOfGuests (ID, TotalNumber) values (11, 'More than 10');


I am having an issue writing a connecting string in VB to connect to this database in VB so i can create buttons and get results from this from oracle.. Any ideas. I have created this connection string in DB to try and connect to oracle but its not working

Imports System.Data
Imports System.Data.Odbc

Public Class Form1

Private Sub btnGetData_Click(sender As System.Object, e As System.EventArgs) Handles btnGetData.Click

Dim dt As New DataTable("myTable")

Dim conn As New OdbcConnection
conn.ConnectionString = "Dsn=ORCL ODBC;uid=com390;pwd=com390;"

conn.Open()

Dim cmd As New OdbcCommand(tbQuery.Text, conn)
cmd.CommandType = CommandType.Text

Dim da As New OdbcDataAdapter(cmd)
da.Fill(dt)

dgvResults.DataSource = dt

lblProductName.Text = dt.Rows(0)("ProductName").ToString()

conn.Close()
conn.Dispose()

End Sub

End Class


I need help....
Posted 14-Dec-12 15:11pm

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

1st Solution::::::::::::
'How to connect Oracle Database from Visual Basic
'Sample code and connection strings to connect Oracle using Visual Basic:

Dim conn As ADODB.Connection

' Open a Conn_Dataection using Oracle ODBC.
Set Conn_Data = New ADODB.Connection
Conn_Data.ConnectionString = "Driver={Microsoft ODBC for Oracle};" & "UID=user_name;PWD=user_passsword"
Conn_Data.Open

'Open the table as in:

Dim rs_Data As ADODB.Recordset

' Open the table.
Set rs_Data = New ADODB.Recordset
rs_Data.Open "TableName", Conn_Data, adOpenDynamic, adLockOptimistic, adCmdTable

'Enter the user name password and table name as per the database.
'it must be valid one.

'To reads the data from the table and displays the values in a ListBox

' List the data.
Do While Not rs_Data.EOF
    txt = ""
    For Each fld In rs_Data.Fields
        txt = txt & Trim$(fld.Value) & ", "
    Next fld
    If Len(txt) > 0 Then txt = Left$(txt, Len(txt) - 2)
    List1.AddItem txt
    rs_Data.MoveNext
Loop

'Finally close the recordset and close the Conn_Dataection:
rs_Data.Close
Conn_Data.Close




IInd Solution:::::::::-----------------------------------------
Dim conv As ADODB.Connection
Dim rsv As ADODB.Recordset
Dim cmdv As ADODB.Command


Private Sub Form_Load()
Set conv = New ADODB.Connection
Set rsv = New ADODB.Recordset
Set cmdv = New ADODB.Command
conv.Open "Provider=MSDASQL.1;Password=tiger;Persist Security Info=True;User ID=scott;Data Source=voter;Initial Catalog=voter"
End Sub


and also check:
1:{ http://niteshpatare.blogspot.com/2010/10/oracle-and-vb-60-connectivity-part-1.html[^]}
  Permalink  
Comments
niteshp27 7-Dec-15 4:54am
   
You can find all the links below.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.161208.2 | Last Updated 7 Dec 2015
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100