Dim Con As OleDbConnection = New OleDbConnection(\"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Music_Sales_Database.mdb;\")
Dim Com As OleDbCommand
Dim Sale
you were required to open connection before the for loop and remove the comment at Command.ExecuteNonQuery()
your code will be as shown below
Dim Con As OleDbConnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Music_Sales_Database.mdb;")
Dim Com As OleDbCommand
Dim SaleCode As Integer
Dim MusicID As String
Dim SubTotalPrice As Decimal
Dim Copies1 As Integer
Dim STR1 As String
SaleCode = 1
Com = New OleDbCommand
Com.Connection = Con
Connection.open()
For x As Integer = 0 To SalesDataGridView.Rows.Count - 1
MusicID = SalesDataGridView.Rows(x).Cells(0).Value
SubTotalPrice = SalesDataGridView.Rows(x).Cells(5).Value
Copies1 = SalesDataGridView.Rows(x).Cells(3).Value
STR1 = "INSERT INTO Sales(Sales_ID, Sales_Date, Copies, Music_ID, Staff_ID, Total_Price) VALUES (@Sales_ID, @Sales_Date, @Copies, @Music_ID, @Staff_ID, @Total_Price)"
Dim Comm As New OleDbCommand(STR1, Con)
Comm.Parameters.AddWithValue("@Sales_ID", SaleCode)
Comm.Parameters.AddWithValue("@Sales_Date", txtDateAndTime)
Comm.Parameters.AddWithValue("@Copies", Copies1)
Comm.Parameters.AddWithValue("@Music_ID", MusicID)
Comm.Parameters.AddWithValue("@Staff_ID", txtStaff_ID)
Comm.Parameters.AddWithValue("@Total_Price", SubTotalPrice)
Command.ExecuteNonQuery()
Comm.Dispose()
Next
Connection.Close()