Search Here

VB Dynamic Form design


VB – ORACLE CONNECTION CODE (Dynamic)
VB Form Design dynamic
Include ADODB Component:
Project à Reference à Microsoft ActiveX Data Objects 2.8 Library
------------------------------------------Code for INSERT-----------------------------------------------------
Private Sub Command1_Click()
Dim MyConn As ADODB.Connection 
Set MyConn = New ADODB.Connection
Dim MyRecSet1 As New ADODB.Recordset
MyConn.ConnectionString = "DSN=conOracle;User Id=scott;Password=tiger;"
MyConn.Open
Set MyRecSet1 = MyConn.Execute("INSERT INTO Student VALUES(" & Val(Text1.Text) & ",'" & Text2.Text & "')")
MyConn.Close
MsgBox ("Add Successfully")
Text1.Text = ""
Text2.Text = ""
End Sub
------------------------------------------Code for Display-----------------------------------------------------
Private Sub Command2_Click()
Dim conn As ADODB.Connection
Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset
Set conn = New ADODB.Connection
Dim i As Integer
conn.ConnectionString = "DSN=conOracle;User Id=scott;Password=tiger;"
conn.Open         
Set rs = conn.Execute("select * from Student")
Text1.Text = rs.Fields(0).Value
Text2.Text = rs.Fields(1).Value
While Not rs.EOF
    i = i + 1
    'MsgBox (rs.Fields("rollno").Value)
    'MsgBox (rs.Fields("name").Value)
    rs.MoveNext
Wend
rs.Close
conn.Close
MsgBox ("no of row = " & i)
End Sub
------------------------------------------Code for Update-----------------------------------------------------
Private Sub Command3_Click()
Dim MyConn As ADODB.Connection
Set MyConn = New ADODB.Connection
Dim MyRecSet1 As New ADODB.Recordset
MyConn.ConnectionString = "DSN=conOracle;User Id=scott;Password=tiger;"
MyConn.Open
Set MyRecSet1 = MyConn.Execute("UPDATE Student SET NAME='" & Text2.Text & "' WHERE ROLLNO=" & CInt(Trim(Text1.Text)) & "")
MyConn.Close
MsgBox ("Update Successfully")
Text1.Text = ""
Text2.Text = ""
End Sub
------------------------------------------Code for DELETE-----------------------------------------------------
Private Sub Command4_Click()
Dim MyConn As ADODB.Connection
Set MyConn = New ADODB.Connection
Dim MyRecSet1 As New ADODB.Recordset
MyConn.ConnectionString = "DSN=conOracle;User Id=scott;Password=tiger;"
MyConn.Open
Set MyRecSet1 = MyConn.Execute("DELETE FROM Student WHERE ROLLNO=" & CInt(Trim(Text1.Text)) & "")
MyConn.Close
MsgBox ("Delete Successfully")
Text1.Text = ""
Text2.Text = ""
End Sub
-------------------------------------------------------------------------------------------------------------

No comments:

Post a Comment