0% found this document useful (0 votes)
4 views3 pages

CC105Notes

Uploaded by

marceloartemio19
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views3 pages

CC105Notes

Uploaded by

marceloartemio19
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Imports System.Data.

OleDb
Module Module1
Public connstr As String = "Provider=Microsoft.Jet.Oledb.4.0; data
source =" & Application.StartupPath & "\studentdb.mdb"
Public conn As New OleDbConnection(connstr)
//this is our module on the previous lesson
Function connect()
If conn.State = ConnectionState.Closed Then
conn.Open()
End If
Return True
End Function
End Module
This is for the form and the global variables to be used
Imports System.Data.OleDb
Public Class Form1
Dim da As New OleDbDataAdapter
Dim dset As New DataSet
Dim Comm As OleDbCommand
Dim code As String
End Class
//this is the code to used for the base load of form 1.
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
populate()
da = New OleDbDataAdapter("Select * from Studentcourse", conn)
dset = New DataSet
da.Fill(dset, "Studentcourse")
Dim count As Integer = dset.Tables("Studentcourse").Rows.Count
Dim x As Integer
For x = 0 To count - 1

CBOCOURSE.Items.Add(dset.Tables("Studentcourse").Rows(x).Item("Cd
es"))
Next
End Sub
//In this you can select the coursecode by selecting course description
//the function populate is used in form load
Function populate()
da = New OleDbDataAdapter("Select * from Studentdata", conn)
dset = New DataSet
da.Fill(dset, "Studentdata")
dgv.DataSource = dset.Tables("Studentdata").DefaultView
Return True
End Function
//finally the command to add a record to the database
Private Sub BADD_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles BADD.Click
code = dset.Tables("Studentcourse").Rows(0).Item("Ccode")
connect()
Comm = New OleDbCommand
Comm.Connection = conn
Comm.CommandText = "Insert into Studentdata values('" &
TXTID.Text & "', '" & TXTFNAME.Text & "', '" & TXTLNAME.Text & "', '" &
code & "', '" & CBOSEC.Text & "')"
Comm.ExecuteNonQuery() //Executes a statement that does not
return a result set, such as an INSERT, UPDATE, DELETE, or data
definition statement.
MsgBox("Succesfully Added into Database")
populate()
End Sub

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy