- Home
- LLBLGen Pro
- LLBLGen Pro Runtime Framework
Update Data Without PK
Joined: 29-Apr-2009
Hi All,
i have read one article & Implement following code to implement Update Operation
CustomersEntity customer = new CustomersEntity();
customer.CustomerId = "ALFKI";
customer.IsNew = false;
customer.Phone = tbphone.Text;
customer.CompanyName = tbcompanyName.Text;
customer.ContactName = tbcontactName.Text;
customer.ContactTitle = tbcontactTitle.Text;
customer.Address = tbaddress.Text;
customer.City = tbcity.Text;
customer.Region = tbregion.Text;
customer.PostalCode = tbpostalcode.Text;
customer.Country = tbcountry.Text;
customer.Fax = tbfax.Text;
customer.Save();
But here the problem is that i want to update data by CompanyName not by CustomerID(Which is PK).
which company name i enter it will update data.
Second Problem is :
the following code is works fine. is there any way to reduce this code
int id = Convert.ToInt32(Request.QueryString["nodeid"]); int intContentDetail=0; ResultsetFields fields = new ResultsetFields(1); fields[0] = CmsContentDetailsFields.IntContentDetailId; PredicateExpression filter = new PredicateExpression(CmsContentDetailsFields.IntNodeId == id); TypedListDAO dao = new TypedListDAO(); IDataReader reader = dao.GetAsDataReader(null, fields, filter, null, CommandBehavior.CloseConnection, 0, true); if (reader.Read()) { intContentDetail = Convert.ToInt32(reader.GetValue(0)); } reader.Close(); CmsContentDetailsEntity CmsContent = new CmsContentDetailsEntity(intContentDetail); CmsContent.TxtMainContent = ((Admin_Editor)fvEditContent.FindControl("EditorContent")).htmlvalue; CmsContent.Save();
Thanks To All
But here the problem is that i want to update data by CompanyName not by CustomerID(Which is PK).
which company name i enter it will update data.
The code should look like:
CustomersCollection customers = new CustomersCollection();
CustomersEntity customer = new CustomersEntity();
customer.Phone = tbphone.Text;
customer.ContactName = tbcontactName.Text;
customer.ContactTitle = tbcontactTitle.Text;
customer.Address = tbaddress.Text;
customer.City = tbcity.Text;
customer.Region = tbregion.Text;
customer.PostalCode = tbpostalcode.Text;
customer.Country = tbcountry.Text;
customer.Fax = tbfax.Text;
IPredicateExpression selectFilter = new PredicateExpression(CustomersFields.CompanyName ==tbcompanyName.Text));
int amountRowsAffected = customers.UpdateMulti(customer, selectFilter, null);
Second Problem is :
the following code is works fine. is there any way to reduce this code
int id = Convert.ToInt32(Request.QueryString["nodeid"]); int intContentDetail=0; ResultsetFields fields = new ResultsetFields(1); fields[0] = CmsContentDetailsFields.IntContentDetailId; PredicateExpression filter = new PredicateExpression(CmsContentDetailsFields.IntNodeId == id); TypedListDAO dao = new TypedListDAO(); IDataReader reader = dao.GetAsDataReader(null, fields, filter, null, CommandBehavior.CloseConnection, 0, true); if (reader.Read()) { intContentDetail = Convert.ToInt32(reader.GetValue(0)); } reader.Close(); CmsContentDetailsEntity CmsContent = new CmsContentDetailsEntity(intContentDetail); CmsContent.TxtMainContent = ((Admin_Editor)fvEditContent.FindControl("EditorContent")).htmlvalue; CmsContent.Save();
What are you trying to achieve by this code?
Joined: 29-Apr-2009
Walaa wrote:
But here the problem is that i want to update data by CompanyName not by CustomerID(Which is PK).
which company name i enter it will update data.
The code should look like:
CustomersCollection customers = new CustomersCollection(); CustomersEntity customer = new CustomersEntity(); customer.Phone = tbphone.Text; customer.ContactName = tbcontactName.Text; customer.ContactTitle = tbcontactTitle.Text; customer.Address = tbaddress.Text; customer.City = tbcity.Text; customer.Region = tbregion.Text; customer.PostalCode = tbpostalcode.Text; customer.Country = tbcountry.Text; customer.Fax = tbfax.Text; IPredicateExpression selectFilter = new PredicateExpression(CustomersFields.CompanyName ==tbcompanyName.Text)); int amountRowsAffected = customers.UpdateMulti(customer, selectFilter, null);
Second Problem is :
the following code is works fine. is there any way to reduce this code
int id = Convert.ToInt32(Request.QueryString["nodeid"]); int intContentDetail=0; ResultsetFields fields = new ResultsetFields(1); fields[0] = CmsContentDetailsFields.IntContentDetailId; PredicateExpression filter = new PredicateExpression(CmsContentDetailsFields.IntNodeId == id); TypedListDAO dao = new TypedListDAO(); IDataReader reader = dao.GetAsDataReader(null, fields, filter, null, CommandBehavior.CloseConnection, 0, true); if (reader.Read()) { intContentDetail = Convert.ToInt32(reader.GetValue(0)); } reader.Close(); CmsContentDetailsEntity CmsContent = new CmsContentDetailsEntity(intContentDetail); CmsContent.TxtMainContent = ((Admin_Editor)fvEditContent.FindControl("EditorContent")).htmlvalue; CmsContent.Save();
What are you trying to achieve by this code?
Hi Walaa,
This is my first project in LLBLGen so getting more problems, actually i am working on other project where i have to bind treeview dynamically, in that user can drag & Drop menu nodes dynamically from admin section, so i need to update all the menunode when it change,so i was first implement basic idea in Northwind database.
In Second Problem first i get one nodevalue by querystring , than i fetch PK value of that query string value and than i update data. so i was asking to update data without using PK, because which value i get in query string that is also unique in my table.
Thanks Walaa, you really help me. . right now it seems difficult for me because i am new in this. i will get very soon command on this.
Thanks Again