This question is locked. New answers and comments are not allowed.
I would like to update my record in the database using OpenAccessContext. I would like to update the Group Table in my database but I don't know how to update it Using DBContext. I can't find the dbContext.SumbitChanges() method. I can just see SaveChanges() method. Any Help would be really appreciated.
Dim txtGroupName As TextBox = e.Item.FindControl("txtGroupName")
Dim groupName As String = txtGroupName.Text
Dim data As GridEditFormItem = e.Item
Dim nID As Integer = Convert.ToInt64(data.ParentItem("ID").Text)
ffGroup.ID = nID
ffGroup.GroupName = groupName
ffGroup.CreatedBy = DotNetNuke.Entities.Users.UserController.GetCurrentUserInfo.UserID
ffGroup.CreatedOn = DateTime.Now
dbContext.Add(ffGroup)
dbContext.SaveChanges()
Dim txtGroupName As TextBox = e.Item.FindControl("txtGroupName")
Dim groupName As String = txtGroupName.Text
Dim data As GridEditFormItem = e.Item
Dim nID As Integer = Convert.ToInt64(data.ParentItem("ID").Text)
ffGroup.ID = nID
ffGroup.GroupName = groupName
ffGroup.CreatedBy = DotNetNuke.Entities.Users.UserController.GetCurrentUserInfo.UserID
ffGroup.CreatedOn = DateTime.Now
dbContext.Add(ffGroup)
dbContext.SaveChanges()
5 Answers, 1 is accepted
0
Hello Muhammad,
Petar
the Telerik team
The SaveChanges method is used for committing your changes to the database. You should use it without a problem.
The code you have provided is used to add a fresh new entry to one of your tables ( representing the type of your ffGroup variable). If you would like to update an instance you will have to first retrieve it from the database and then alter its properties and call SaveChanges. I believe that our getting started guide available in our online documentation will prove to be a great start for you.
Petar
the Telerik team
Do you want to have your say when we set our development plans?
Do you want to know when a feature you care about is added or when a bug fixed?
Explore the
Telerik Public Issue Tracking
system and vote to affect the priority of the items
0
Muhammad
Top achievements
Rank 1
answered on 21 Apr 2011, 12:44 PM
Can you please tell me that how can I retrieve that record from database using OpenAccessContext ... and update that record.
0
Hi Muhammad,
So what you should do is call
in order to obtain the ffGroup object with the desired ID. Then you just set the properties as you would like to and call SaveChanges()(without calling dbContext.Add() as you previously did).
Zoran
the Telerik team
You can obtain the existing record using Linq query or by using the GetObjectByKey method. I will show you the later approach in the following code snippet:
Dim txtGroupName As TextBox = e.Item.FindControl("txtGroupName") Dim groupName As String = txtGroupName.Text Dim data As GridEditFormItem = e.Item Dim nID As Integer = Convert.ToInt64(data.ParentItem("ID").Text) ffGroup = dbContext.GetObjectByKey(New ObjectKey(ffGroup.GetType().Name, nID)) ffGroup.GroupName = groupName ffGroup.CreatedBy = DotNetNuke.Entities.Users.UserController.GetCurrentUserInfo.UserID ffGroup.CreatedOn = DateTime.Now dbContext.SaveChanges()So what you should do is call
ffGroup = dbContext.GetObjectByKey(NewObjectKey(ffGroup.GetType().Name, nID))
in order to obtain the ffGroup object with the desired ID. Then you just set the properties as you would like to and call SaveChanges()(without calling dbContext.Add() as you previously did).
Zoran
the Telerik team
Do you want to have your say when we set our development plans?
Do you want to know when a feature you care about is added or when a bug fixed?
Explore the
Telerik Public Issue Tracking
system and vote to affect the priority of the items
0
Muhammad
Top achievements
Rank 1
answered on 05 May 2011, 05:16 PM
Thank you so much ... Is it possible that I can retrieve the ID of inserted record ... ? ID is the primary key value in my table.
0