andrewmanuja
Well-known member
- Joined
- May 30, 2019
- Messages
- 75
- Programming Experience
- Beginner
Hi All,
I am currently working on getting
Please find the respective Data Access Layer code below;
My Business Logic Layer code looks like below;
I am bit confused how to write the code for the btnUpdate (Update button) to update the datagridview data to the database table. Is it just to call the Business Access Layer "UpdateUser" method?
Just a small clarification, Since I have bind the datatable, "table" as the dataGridView's datasource, I assume whatever the changes I perform to the datagridview cell data automatically updates the datatable, "table'.
Appreciate your feedback.
Kind regards,
Andrew
I am currently working on getting
Please find the respective Data Access Layer code below;
C#:
public void UpdateUser(PersonDTO bPerson)
{
using (SqlConnection conn = new SqlConnection(_connStr))
using (var dCmd = new SqlCommand(@"UPDATE Person SET FirstName = @FirstName, LastName = @LastName, Age = @Age WHERE PersonID = @PersonID", conn))
using (var adapter = new SqlDataAdapter { UpdateCommand = dCmd })
{
conn.Open();
dCmd.Parameters.AddWithValue("personID", bPerson.PersonID);
dCmd.Parameters.AddWithValue("firstName", bPerson.FirstName);
dCmd.Parameters.AddWithValue("lastName", bPerson.LastName);
dCmd.Parameters.AddWithValue("age", bPerson.Age);
try
{
adapter.Update(table);
dCmd.Dispose();
}
catch (Exception ex)
{
throw ex;
}
}
foreach (DataRow row in table.Rows)
{
if (row["Select Item"] as bool? == true)
{
table.AcceptChanges();
row.SetAdded();
}
}
}
My Business Logic Layer code looks like below;
C#:
public void UpdateUser(PersonDTO bPerson)
{
try
{
personDAL.UpdateUser(bPerson);
}
catch (Exception ex)
{
throw ex;
}
}
I am bit confused how to write the code for the btnUpdate (Update button) to update the datagridview data to the database table. Is it just to call the Business Access Layer "UpdateUser" method?
Just a small clarification, Since I have bind the datatable, "table" as the dataGridView's datasource, I assume whatever the changes I perform to the datagridview cell data automatically updates the datatable, "table'.
Appreciate your feedback.
Kind regards,
Andrew