Skip to main content

Oracle and VB 6.0 Connectivity (Part 3)

Now we will see how to insert values into table a table and to view them.

Oracle
Initially we had created table in part1.

Visual Basic 6.0
Now we wil insert data into the table through visual basic.

The code for inserting will be as follows
When you double click on add button it will open your code window it will have this code!

Private Sub Command1_Click()
Dim gen As String
If (Option1.Value = True) Then
gen = "male"
ElseIf (Option2.Value = True) Then
gen = "female"
End If
rsv.Open "insert into voter values(" & Text5.Text & ",'" & Text2.Text & "','" & Text3.Text & "','" & Combo1.Text & "','" & gen & "','" & DTPicker1.Value & "')", conv, adOpenDynamic, adLockOptimistic
If (rsv.State = 1) Then
rsv.Close
End If
MsgBox ("Data Entered")
End Sub

This will add the data entered into the fields into the oracle database.

Next is to view this entered data from table.

Visual basic code
Private Sub Command7_Click()
Dim viewv As Integer
viewv = InputBox("enter the voter id")

rsv.Open "select id,name,address,age,gender,dob from voter where id=' " & viewv & " '", conv, adOpenDynamic, adLockOptimistic

Text5.Text = rsv.Fields("id")
Text2.Text = rsv.Fields("name")
Text3.Text = rsv.Fields("address")
Combo1.Text = rsv.Fields("age")

If (rsv.Fields("gender") = "male") Then
Option1.Value = True
ElseIf (rsv.Fields("gender") = "female") Then
Option2.Value = True
End If

DTPicker1.Value = rsv.Fields("dob")

If (rsv.State = 1) Then
rsv.Close
End If
MsgBox "view"
End Sub

You are done! In the next part you will see procedures! in part 4.
Part 4

Comments

  1. How To manage when multiple rows get selected from the Query??

    ReplyDelete
  2. hw to exract frm database to datagrid

    ReplyDelete
  3. i connected database but when i insert it tells "system.mine trigger is not valid and failed re validation"
    for this error what is a solution..
    i did alll steps as tell above...
    any one can help me out...????

    ReplyDelete
  4. Private Sub insert_Click()
    Set con = New ADODB.Connection
    Set rec = New ADODB.Recordset
    With con
    .CursorLocation = adUseClient
    .ConnectionString = "Provider=MSDASQL.1;Password=tiger;Persist Security Info=True;User ID=system;Data Source=tiger;Initial Catalog=tiger"
    .Open
    End With
    rec.Open "tiger", con, adOpenDynamic, adLockBatchOptimistic, adCmdTable
    Dim gen As String
    rec.Open "insert into tiger values (' " & Text1.Text & " ' ," & Text2.Text & " ," & Text3.Text & ")", con, adOpenDynamic, adLockOptimistic
    If (rec.State = 1) Then
    rec.Close
    End If
    MsgBox ("data entered")
    this is my coding for my insert button..
    i got error that "operation is not allowed when object is open"
    help me out...

    ReplyDelete

Post a Comment

Popular posts from this blog

Oracle and VB 6.0 Connectivity (Part 1)

Here is a basic VB application called voter information system demonstrated which explains the concepts quite clearly. The first step required to establish connectivity is preparing the back end and the front end of the project. These steps are divided into two parts first the back end that is the oracle and front end that is the Visual Basic 6.0. Oracle Firstly we need to set up the database. Create the tables, triggers and procedures and database in the oracle. Create tables: Example: create table voter(id number(5) primary key, name varchar2(25),address varchar2(50),age number(3),gender varchar2(6),dob varchar2(30)); create table votertemp(id number(5) primary key, name varchar2(25),address varchar2(50),age number(3),gender varchar2(6),dob varchar2(30)); (we will be using the next table in the triggers that we will be implementing) Visual Basic 6.0 Develop the VB application as in this example given below. Design the necessary forms for the application. The next part is

Validations in Visual Basic 6.0

This topic will demonstrate how to perform client side validations in Visual Basic 6.0. It will guide you with a step by step procedure. 1) Firstly in the below image suppose you want to accept only integer numbers as id in the textbox next to ID label in the form from the user you can perform client side validations in the following way: These are the ascii codes that i am using for acepting only integer values from user. Back space - 8 0 to 9 Integers - 48 to 57 Delete - 127 This is how the function will look. Private Sub Text2_KeyPress(KeyAscii As Integer) If Not ((KeyAscii >= 48 And KeyAscii <= 57) Or KeyAscii = 127 Or KeyAscii = 8) Then MsgBox "enter proper value" KeyAscii = 0 End If End Sub Double click on the text box which you want to validate. Next select the event as keypress from top right list box. In this case the name of text box is text1. This is the function for accepting input as integer value only from the user.