View
237
Download
0
Category
Preview:
Citation preview
8/2/2019 VB N ORA PGMS
1/29
8/2/2019 VB N ORA PGMS
2/29
8/2/2019 VB N ORA PGMS
3/29
8/2/2019 VB N ORA PGMS
4/29
8/2/2019 VB N ORA PGMS
5/29
8/2/2019 VB N ORA PGMS
6/29
8/2/2019 VB N ORA PGMS
7/29
Program-1
Dim n1 As IntegerDim BINARY, OCTAL As SingleDim HEX As String
Private Sub Command1_Click()n1 = Val(Text1.Text)Text2.Text = ""Do While (n1 0)BINARY = n1 Mod 2n1 = n1 \ 2Text2.Text = BINARY & Text2.TextLoopEnd Sub
Private Sub Command2_Click()n1 = Val(Text1.Text)Text3.Text = ""Do While (n1 0)octl = n2 Mod 8n1 = n2 \ 8Text3.Text = OCTAL & Text3.TextLoopEnd Sub
Private Sub Command3_Click()
N3= Val(Text1.Text)Text4.Text = ""Do While (n1 0)HEX = n3 Mod 16n1 = n3 \ 16If (HEX >= 10) ThenSelect Case (HEX)Case 10:hexa = "a"Case 11:hexa = "b"
Case 12:hexa = "c"Case 13:hexa = "d"Case 14:hexa = "e"Case 15:hexa = "f"
8/2/2019 VB N ORA PGMS
8/29
End SelectEnd IfText4.Text = HEX & Text4.TextLoopEnd Sub
Private Sub Command4_Click()Text1.Text = ""Text2.Text = ""Text3.Text = ""Text4.Text = ""Text1.SetFocusEnd Sub
Private Sub Command5_Click()End
End sub
Program-2
Private Sub Command1_Click()
8/2/2019 VB N ORA PGMS
9/29
List1.AddItem (Text1.Text)End Sub
Private Sub Command2_Click()Combo1.AddItem (List1.Text)
End Sub
Private Sub Command3_Click()Text1.Text = ""List1.ClearCombo1.ClearText1.SetFocusEnd Sub
Private Sub Command4_Click()End
End Sub
Program-3
Public cval As DoublePublic pval As DoublePublic res As DoublePublic ch As String
8/2/2019 VB N ORA PGMS
10/29
Private Sub cmdac_Click(Index As Integer)Text1.Text = ""pval = cvalEnd Sub
Private Sub cmdadd_Click(Index As Integer)Text1.Text = ""pval = cvalch = "+"End Sub
Private Sub cmddiv_Click(Index As Integer)Text1.Text = ""pval = cvalcval = 0ch = "/"
End Sub
Private Sub cmdequ_Click(Index As Integer)Select Case chCase Is = "+"res = pval + cvalText1.Text = Str(res)Case Is = "-"res = pval - cvalText1.Text = Str(res)Case Is = "*"
res = pval * cvalText1.Text = Str(res)Case Is = "/"res = pval / cvalText1.Text = Str(res)End Selectcval = resEnd Sub
Private Sub Cmdmin_Click(Index As Integer)
Text1.Text = ""pval = cvalcval = 0ch = "-"
End Sub
Private Sub cmdmul_Click(Index As Integer)
8/2/2019 VB N ORA PGMS
11/29
Text1.Text = ""pval = cvalch = "*"End Sub
Private Sub Command1_Click(Index As Integer)Text1.Text = Text1.Text & Command1(Index).Captioncval = Val(Text1.Text)End Sub
Private Sub Command2_Click()EndEnd Sub
Program-4
Private Sub mnufont_Click()CommonDialog1.Flags = cd / cfbothCommonDialog1.ShowFontRichTextBox1.setfontname = CommonDialog1.FontNameRichTextBox1.setfontsize = CommonDialog1.FontSizeRichTextBox1.setfontbold = CommonDialog1.FontBoldRichTextBox1.setfontitalic = CommonDialog1.FontItalicEnd Sub
8/2/2019 VB N ORA PGMS
12/29
Private Sub mnunew_Click()RichTextBox1.Text = ""End Sub
Private Sub mnuopen_Click()CommonDialog1.Filter = "textfiles(*.text)/*.text/alfiles(*.*)/*.*"CommonDialog1.ShowOpenRichTextBox1.LoadFile (CommonDialog1.FileName)End Sub
Private Sub mnusave_Click()CommonDialog1.Filter = "textfiles(*.text)/*.text/alfiles(*.*)/*.*"CommonDialog1.ShowSaveRichTextBox1.SaveFile (CommonDialog1.FileName)End Sub
Program-5
Dim db As DatabaseDim rs As RecordsetDim score As IntegerDim m1 As String
Private Sub Command1_Click()rs.MoveNextIf Not rs.EOF ThenLabel1.Caption = rs(0)Label2.Caption = rs(1)Option1.Caption = rs(2)Option2.Caption = rs(3)
8/2/2019 VB N ORA PGMS
13/29
Option3.Caption = rs(4)ElseCommand1.Enabled = FalseMsgBox ("ur score is" & score)End If
End Sub
Private Sub Command2_Click()EndEnd Sub
Private Sub Form_Load()Set db = OpenDatabase("C:\Documents and Settings\Admin\MyDocuments\suji.mdb")Set rs = db.OpenRecordset("select * from neshu")score = 0
If Not rs.EOF Thenrs.MoveFirstLabel1.Caption = rs(0)Label2.Caption = rs(1)Option1.Caption = rs(2)Option2.Caption = rs(3)Option3.Caption = rs(4)End IfEnd Sub
Private Sub Option1_Click()
If Option1.Value = True Thenm1 = StrComp(Option1.Caption, rs.Fields(5))If m1 = 0 Thenscore = Val(score) + 1End IfEnd IfEnd Sub
8/2/2019 VB N ORA PGMS
14/29
Program-6
Private Sub mnuadd_Click()Dim newform As Form1Set newform = New Form1newform.ShowEnd Sub
Private Sub mnucascade_Click()
Me.Arrange vbTileHorizontalEnd Sub
Private Sub mnucolor_Click()CommonDialog1.ShowColorMDIForm1.ActiveForm.BackColor = CommonDialog1.ColorEnd Sub
8/2/2019 VB N ORA PGMS
15/29
PROGRAM 7
Creation of table category_headSQL> create table category_head(category_code varchar2(20) primary key);Table created.
Creation of table route_headSQL> create table route_head(route_id varchar2(20) primary key,category_code varchar2(20) references category_head(category_code));Table created.
Creation of table ticket_headSQL> create table ticket_head(ticket_no varchar2(20) primary key);Table created.
Creation of table place_headSQL> create table place_head(place_id varchar2(20) primary key);Table created.
8/2/2019 VB N ORA PGMS
16/29
Creation of table ticket_detailSQL> create table ticket_detail(ticket_no varchar2(20) referencesticket_head(ticket_no));Table created.
Creation of table route_detailSQL> create table route_detail(place_id varchar2(20) referencesplace_head(place_id),route_id varchar2(20) referencesroute_head(route_id));Table created.
Altering of table ticket_headSQL> alter table ticket_head add constraint chk check(ticket_no alter table route_head add distance long;Table altered.
PROGRAM 8
Inserting values into category_headSQL> insert into category_head values('mdr 2 chn');1 row created.
SQL> insert into category_head values('mdr 2 cbe');1 row created.
SQL> insert into category_head values('cbe 2 chn');1 row created.
SQL> insert into category_head values('cbe 2 blr');1 row created.
SQL> insert into category_head values('blr 2 chn');1 row created.
Inserting values into route_head
8/2/2019 VB N ORA PGMS
17/29
SQL> insert into route_head values('mr 2 cn','mdr 2 chn', 450);1 row created.
SQL> insert into route_head values('mr 2 ce','mdr 2 cbe',360);1 row created.
SQL> insert into route_head values('ce 2 cn','cbe 2 chn',560);1 row created.
SQL> insert into route_head values('ce 2 br','cbe 2 blr',240);1 row created.
SQL> insert into route_head values('br 2 cn','blr 2 chn',520);1 row created.
Inserting values into ticket_head
SQL> insert into ticket_head values(42);1 row created.
SQL> insert into ticket_head values(56);1 row created.
SQL> insert into ticket_head values(74);1 row created.
SQL> insert into ticket_head values(36);1 row created.
SQL> insert into ticket_head values(134);1 row created.
Inserting values into place_head
SQL> insert into place_head values(100);1 row created.
SQL> insert into place_head values(123);1 row created.
SQL> insert into place_head values(146);1 row created.
SQL> insert into place_head values(172);1 row created.
SQL> insert into place_head values(183);
8/2/2019 VB N ORA PGMS
18/29
1 row created.
Inserting values into route_detail
SQL> insert into route_detail values(100,'mr 2 cn');1 row created.
SQL> insert into route_detail values(123,'mr 2 ce');1 row created.
SQL> insert into route_detail values(146,'ce 2 cn');1 row created.
SQL> insert into route_detail values(172,'ce 2 br');1 row created.
SQL> insert into route_detail values(183,'br 2 cn');1 row created.
Inserting values into ticket_detail.SQL> insert into ticket_detail values(42);1 row created.
SQL> insert into ticket_detail values(56);1 row created.
SQL> insert into ticket_detail values(74);1 row created.
SQL> insert into ticket_detail values(36);1 row created.
SQL> insert into ticket_detail values(134);1 row created.
Altering table route_detailSQL> alter table route_detail add source varchar2(20);Table altered.
SQL> alter table route_detail add destination varchar2(20);Table altered.
8/2/2019 VB N ORA PGMS
19/29
Updating table route_detail with source and destination
SQL> update route_detail set source='madras', destination='cochin'whereplace_id=100;1 row updated.
SQL> update route_detail set source='madras',destination='coimbatore'where place_id=123;1 row updated.
SQL> update route_detail set source='coimbatore', destination='cochin'where place_id=146;1 row updated.
SQL> update route_detail set source='coimbatore', destination='bangalore'where place_id=172;
1 row updated.
SQL> update route_detail set source='bangalore', destination='cochin'where place_id=183;1 row updated.
updating route_head with distance 500SQL> update route_head set distance=500 where route_id='mr 2 ce';1 row updated.PROGRAM 99a.Select rows from ticketdetail such that ticket number greater
than ticket number in ticket headCreating table ticketheadSQL> create table thead(tno number(5),destination varchar2(20));Table created.
Inserting values into table ticketheadSQL> insert into thead values(100,'Salem');1 row created.
SQL> insert into thead values(101,'Bombay');1 row created.
SQL> insert into thead values(102,'Coimbatore');1 row created.
Creating table ticketdetailSQL> create table ticdetail(tno number(5),amount number(12,2),destinationvarchar2(20),datesval date);Table created.
8/2/2019 VB N ORA PGMS
20/29
Inserting values into table ticdetailSQL> insert into ticdetail values(102,30,'Erode','10-jan-2009');1 row created.
SQL> insert into ticdetail values(110,40,'Avinashi','2-mar-2009');1 row created.
SQL> insert into ticdetail values(115,50,'Ooty','19-mar-2009');1 row created.
9b. Select rows from rhead such that rid greater than rid ofroutedetail & pid should be 100Creating table rheadSQL> create table rhead(rid number(5),pid number(5))
Table created.
Inserting values into rheadSQL> insert into rhead values(1001,111);1 row created.
SQL> insert into rhead values(1002,112);1 row created.
SQL> insert into rhead values(1003,113);1 row created.
SQL> insert into rhead values(1004,114);1 row created.
SQL> insert into rhead values(1005,100);1 row created.
SQL> insert into rhead values(1006,100);1 row created.
SQL> insert into rhead values(1007,100);
1 row created.
9c.Create view from ticket_header with tno,origin,destination,rid
8/2/2019 VB N ORA PGMS
21/29
Creating table ticket_headerSQL> create table ticket_header(tno number(5),rid number(3),originvarchar2(20),destination varchar2(20));Table created.
Inserting into table ticket_headerSQL> insert into ticket_header values(100,10,'Coimbatore','Salem');1 row created.
SQL> insert into ticket_header values(101,11,'Coimbatore','chennai');1 row created.
Creating viewSQL> create view ticketheadview(tno,rid,origin,destination)as select * fromticket_header;View created.
PROGRAM 10
Creation of table ticketdetailSQL> create table tdetail (tno number(5), amt number(12,2),destination
varchar2(30),datesval date);Table created.
Inserting values into ticketdetailSQL> insert into tdetail values(1000,450,'Hyderbad','12-feb-2009');1 row created.
SQL> insert into tdetail values(1001,600,'Bombay','19-mar-2009');1 row created.
SQL> insert into tdetail values(1002,250,'Chennai','2-apr-2009');
1 row created.
8/2/2019 VB N ORA PGMS
22/29
PROGRAM 11
Creating table placeheadSQL> create table placehead(place_id number(2),busstation char(30));Table created.
Inserting values into table placehead.SQL> insert into placehead values(01,'Chennai');1 row created.
SQL> insert into placehead values(02,'bangalore');1 row created.
SQL> insert into placehead values(03,'Coimbatore');1 row created.
SQL> insert into placehead values(04,'Madurai');
1 row created.
SQL> insert into placehead values(05,'Trichi');1 row created.
PL/SQL statement to update busstation valuesSQL> begin
8/2/2019 VB N ORA PGMS
23/29
2 update placehead set busstation='Erode' where place_id=01 orplace_id=05;
3 end;4 /
PL/SQL procedure successfully completed.
Creating table routedetailSQL> create table rou_detail(rid number(3), distance number(3), amountnumber (12, 2), day char(20));Table created.
SQL> insert into rou_detail values (100,10,12.34,'Monday');1 row created.
PL/SQL to update the amount valuesSQL> declare
2 v_rid rou_detail.rid%type;3 begin4 update rou_detail set amount=200 where rid=&v_rid and distance
8/2/2019 VB N ORA PGMS
24/29
Trigger created.
Inserting values into routedetailSQL> insert into rou_detail values(1,2,13,'tuesday');1 row created.
Trigger for deletionSQL> create or replace trigger mtrig
2 before delete on rou_detail3 begin4 raise_application_error(-20002,'All records will be deleted which can not
be retrieved');5 end;6 /
Trigger created.
PROGRAM -12
Private Sub CmdAdd_Click()Adodc1.Recordset.AddNew
MsgBox "records added"End Sub
Public Sub CmdClear_Click()Text1.Text = ""Text2.Text = ""Text3.Text = ""Text4.Text = ""Text5.Text = ""End Sub
Private Sub CmdDelete_Click()Adodc1.Recordset.DeleteMsgBox "records deleted"End Sub
Private Sub Cmdend_Click()EndEnd Sub
8/2/2019 VB N ORA PGMS
25/29
Private Sub CmdMoveFirst_Click()Adodc1.Recordset.MoveFirstEnd Sub
Private Sub CmdMoveLast_Click()If Not (Adodc1.Recordset.BOF) ThenAdodc1.Recordset.MoveLastElseMsgBox "no records"End IfEnd Sub
Private Sub CmdMoveNext_Click()If Not (Adodc1.Recordset.EOF) Then
Adodc1.Recordset.MoveNextElseMsgBox "no records"End IfEnd Sub
Private Sub CmdMovePrevious_Click()Adodc1.Recordset.MovePreviousEnd Sub
Private Sub CmdUpdate_Click()
Adodc1.Recordset.UpdateMsgBox "records updated"End Sub
Private Sub display()Text1.Text = Adodc1.Recordset("rno")Text2.Text = Adodc1.Recordset("name")Text3.Text = Adodc1.Recordset("class")Text4.Text = Adodc1.Recordset("address")Text5.Text = Adodc1.Recordset("phno")End Sub
Private Sub Form_Load()Form2.WindowState = 2End Sub
8/2/2019 VB N ORA PGMS
26/29
8/2/2019 VB N ORA PGMS
27/29
SQL STATEMENTS
SQL>create table stu_mas(rno varchar2(20),name varchar2(20),classvarchar2(20),address varchar2(20),phno number(10));
Table created
SQL> desc stu_mas;Name Null? Type------------------------------- -------- ----RNO VARCHAR2(10)
NAME VARCHAR2(20)CLASS VARCHAR2(20)ADDRESS VARCHAR2(20)PHNO NUMBER(10)
SQL> insert into stu_masvalues(114,'girija','bcom','thirunagar',9897654321);1 row created.
8/2/2019 VB N ORA PGMS
28/29
SQL> insert into stu_mas values(115,'rajesh','bca','ashoknagar',9994654321);1 row created.
SQL> insert into stu_masvalues(116,'harish','ecs','coimbatore',9897687124);1 row created.
SQL> select * from stu_mas;
RNO NAME CLASS ADDRESS PHNO---------- -------------------- -------------------- -------------------- ---------114 girija bcom thirunagar 9.898E+09
115 rajesh bca ashok nagar 9.995E+09101 harish ecs coimbatore 9.898E+09
Note:For connecting Oracle database
1. Goto start menusettingcontrol panelperformance and
maintenanceadministrative toolsdata source(ODBC)2. double click data source(ODBC): ODBC data source administrator
opens
3. Select add from user DSN create new data source window appearsselect Microsoft ODBC for oracle.
4. Click finish.5. Microsoft ODBC for oracle setup window appears with text areas6. Fill DSN name, user name and server as any name , scott , oracle.7. Click ok.8. your DSN name appears in the user DSN tab9. Click ok.10. close the control panel.
VB
1. Go to components and select Microsoft ADO Data Control 6.0(OLEDB)2. drag and drop the adodc control from tools of vb to from3. go to reference and select the following4. set the password as tiger and user name as scott in adodc property5. set the recordsource of adodc in adodc property(select the table name
from oracle)6. set the datafield and datasource for all the text boxes individually.
8/2/2019 VB N ORA PGMS
29/29
Recommended