Question 3 Tier Question

dfenton21

Member
Joined
Apr 26, 2011
Messages
20
Programming Experience
Beginner
I'm learning VB.Net while developing a three tier database application. So far, the values for my database records came from textboxes and comboboxes. I passed these values to my DAL (via the BLL) and updated the database using paramatised SQL.

I now need to update a database table using a DGV. I can do that if the data access code is contained within the form class, but that is obviously bad practice because the presentation layer shouldn't communicate directly with the database.

I need to know how to pass the DGV's information (that the user has changed) to the DAL.

The code I currently have for updating the database directly from the PL is:

VB.NET:
Dim dbConnection As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source='C:\Documents and Settings\Damien Fenton\Desktop\VBNET Projects\SkillSet\SkillSetDB.mdb'")
        Dim commandString As String = "UPDATE Bookings SET AttendenceNotes = @Result WHERE BookingId = @BookingId"

        Dim dbCommand As New OleDbCommand(commandString, dbConnection)


        dbConnection.Open()

        For Each row As DataGridViewRow In dgvAttendence.Rows


            Dim ResultParam As New OleDbParameter("@Result", OleDbType.VarChar, 20)
            ResultParam.Value = row.Cells("colAttendence").Value.ToString
            dbCommand.Parameters.Add(ResultParam)

            Dim IdParam As New OleDbParameter("@BookingId", OleDbType.VarChar, 20)
            IdParam.Value = CInt(row.Cells("BookingId").Value.ToString)
            dbCommand.Parameters.Add(IdParam)


            dbCommand.ExecuteNonQuery()
            dbCommand.Parameters.Clear()

        Next row
        dbConnection.Close()
Any code examples or advice on how to do this would be highly appreciated.

Thanks
 
Back
Top