This code defines a class that connects to an Oracle database and retrieves and inserts data. It establishes a connection to an Oracle database using the connection string. It has two button click events, one that retrieves data from a table using a data adapter and fills a dataset, looping through the rows to populate textboxes. The other uses a data adapter to insert a new row with values from textboxes into a table. Any exceptions are caught and displayed in a message box.
Download as DOC, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
23 views
Vbcode
This code defines a class that connects to an Oracle database and retrieves and inserts data. It establishes a connection to an Oracle database using the connection string. It has two button click events, one that retrieves data from a table using a data adapter and fills a dataset, looping through the rows to populate textboxes. The other uses a data adapter to insert a new row with values from textboxes into a table. Any exceptions are caught and displayed in a message box.
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 1
Imports System.
Data Imports System.Data.oracleclient
Public Class Form1
Public con As OracleConnection
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load con = New OracleConnection("DATA SOURCE=orcl;USER ID=system;PASSWORD=happy") End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click Try Dim da As OracleDataAdapter Dim ds As DataSet = New DataSet Dim dt As DataTable Dim dr As DataRow da = New OracleDataAdapter("select * from bhaodb", con) Dim cm As New OracleCommandBuilder(da) da.Fill(ds, "bhaodb") dt = ds.Tables(0) For Each dr In dt.Rows TextBox1.Text = dr.Item(0) TextBox2.Text = dr.Item(1) Next Catch ex As Exception MsgBox(ex.ToString) End Try End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click Try Dim da As OracleDataAdapter Dim ds As DataSet = New DataSet Dim dt As DataTable Dim dr As DataRow da = New OracleDataAdapter("select * from bhaodb", con) Dim cm As New Oraclecommandbuilder(da) da.fill(ds, "bhaodb") dt = ds.Tables(0) dr = dt.NewRow dr.Item(0) = TextBox3.Text dr.Item(1) = TextBox4.Text dt.Rows.Add(dr) da.update(ds, "bhaodb") Catch ex As Exception MsgBox(ex.ToString) End Try End Sub End Class