Hello, I am a BEGINNER using Microsoft Visual Studio as my coding program. This
ID: 3821720 • Letter: H
Question
Hello, I am a BEGINNER using Microsoft Visual Studio as my coding program. This project comes from the "Microsoft Visual Basic 2015 RELOADED" book, chapter 12, page 654, case project College Courses.
Here is the problem:
In this Case Project, you use a Microsoft Access database named Courses. The database is stored in the VbReloaded2015Chap12Access DatabasesCourses.accdb file. The database contains one table named tblCourses. Each record has the following four fields: ID, Title, CreditHours, and Grade. The CreditHours field is numeric; the other fields contain text. Create an application that allows the user to display the records for a specific grade (A, B, C, D, or F). The user should also be able to display all of the records. Display the records in a DataGridView control. The application should not allow the user to add, edit, delete, or save records. Include
a Calculate GPA button on the BindingNavigator control. The button’s Click event procedure should display the student’s GPA. An A grade is worth 4 points, a B is worth 3 points, and so on. Use the following names for the solution and project, respectively: College Courses Solution and College Courses Project. Save the application in the VbReloaded2015Chap12 folder. Change the form file’s name to Main Form.vb.
Here is the Access file:
I have to use Microsoft Visual Studio as my coding program and I am a BEGINNER.
Thank you very much for your help/work with this problem!
Explanation / Answer
First we must add the following declaration
Public Class Form1
Dim connString As String = "Provider=Microsoft.ACE.OLEDB.12.0; Data Source=VbReloaded2015Chap12Access DatabasesCourses.accdb"
Dim MyConn As OleDbConnection
Dim da As OleDbDataAdapter
Dim ds As DataSet
Dim tables As DataTableCollection
Dim source1 As New BindingSource
Then on the click of the Button
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
MyConn = New OleDbConnection
MyConn.ConnectionString = connString
ds = New DataSet
tables = ds.Tables
da = New OleDbDataAdapter("Select * from [items]", MyConn) 'Change items to your database name
da.Fill(ds, "items") 'Change items to your database name
Dim view As New DataView(tables(0))
source1.DataSource = view
DataGridView1.DataSource = view
End Sub
Public Class Form1
Dim connString As String = "Provider=Microsoft.ACE.OLEDB.12.0; Data Source=VbReloaded2015Chap12Access DatabasesCourses.accdb"
Dim MyConn As OleDbConnection
Dim da As OleDbDataAdapter
Dim ds As DataSet
Dim tables As DataTableCollection
Dim source1 As New BindingSource
Then on the click of the Button
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
MyConn = New OleDbConnection
MyConn.ConnectionString = connString
ds = New DataSet
tables = ds.Tables
da = New OleDbDataAdapter("Select * from [items]", MyConn) 'Change items to your database name
da.Fill(ds, "items") 'Change items to your database name
Dim view As New DataView(tables(0))
source1.DataSource = view
DataGridView1.DataSource = view
End Sub
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.