Insert opertion doesn't work
-
I am doing an insert opertion here in this code but when I opened table it shows blank rows.
namespace DAL { public class DALCustomerEntery { NorthwindMapping.NorthwindDataContext xy = new NorthwindMapping.NorthwindDataContext(); public void InsertData(Customer objCustObj) //this object is coming from BOL { NorthwindMapping.Customer cust= new NorthwindMapping.Customer(); cust.CustName = objCustObj.Custname; cust.amount = 25.89D; cust.Companyname = "My company"; cust.Checkin = DateTime.Now; cust.Checkout = DateTime.Now; xy.Customers.InsertOnSubmit(cust); xy.SubmitChanges(); } } }
Any help would be appreciated. Thanks. -
I am doing an insert opertion here in this code but when I opened table it shows blank rows.
namespace DAL { public class DALCustomerEntery { NorthwindMapping.NorthwindDataContext xy = new NorthwindMapping.NorthwindDataContext(); public void InsertData(Customer objCustObj) //this object is coming from BOL { NorthwindMapping.Customer cust= new NorthwindMapping.Customer(); cust.CustName = objCustObj.Custname; cust.amount = 25.89D; cust.Companyname = "My company"; cust.Checkin = DateTime.Now; cust.Checkout = DateTime.Now; xy.Customers.InsertOnSubmit(cust); xy.SubmitChanges(); } } }
Any help would be appreciated. Thanks. -
Hi! Have you got the primary keys defined correct in the dbml file?
Andreas Johansson
IT Professional at Office IT Partner i Norrbotten Sweden
What we don't know. We learn.
What you don't know. We teachYes
-
Yes
-
Have you tried to instansiate the DataContext object within the method?
Andreas Johansson
IT Professional at Office IT Partner i Norrbotten Sweden
What we don't know. We learn.
What you don't know. We teachCould you please refer the code in my first post ? and according can you provide me the hint?
-
Could you please refer the code in my first post ? and according can you provide me the hint?
You wrote:
namespace DAL
{
public class DALCustomerEntery
{
NorthwindMapping.NorthwindDataContext xy = new NorthwindMapping.NorthwindDataContext();public void InsertData(Customer objCustObj) //this object is coming from BOL
{NorthwindMapping.Customer cust= new NorthwindMapping.Customer();
cust.CustName = objCustObj.Custname;
cust.amount = 25.89D;
cust.Companyname = "My company";
cust.Checkin = DateTime.Now;
cust.Checkout = DateTime.Now;xy.Customers.InsertOnSubmit(cust);
xy.SubmitChanges();
}
}
}try to move the row
NorthwindMapping.NorthwindDataContext xy = new NorthwindMapping.NorthwindDataContext();
into the InsertData Methodnamespace DAL
{
public class DALCustomerEntery
{public void InsertData(Customer objCustObj) //this object is coming from BOL
{
NorthwindMapping.NorthwindDataContext xy = new NorthwindMapping.NorthwindDataContext();
NorthwindMapping.Customer cust= new NorthwindMapping.Customer();cust.CustName = objCustObj.Custname;
cust.amount = 25.89D;
cust.Companyname = "My company";
cust.Checkin = DateTime.Now;
cust.Checkout = DateTime.Now;xy.Customers.InsertOnSubmit(cust);
xy.SubmitChanges();
}
}
}Andreas Johansson
IT Professional at Office IT Partner i Norrbotten Sweden
What we don't know. We learn.
What you don't know. We teach -
I am doing an insert opertion here in this code but when I opened table it shows blank rows.
namespace DAL { public class DALCustomerEntery { NorthwindMapping.NorthwindDataContext xy = new NorthwindMapping.NorthwindDataContext(); public void InsertData(Customer objCustObj) //this object is coming from BOL { NorthwindMapping.Customer cust= new NorthwindMapping.Customer(); cust.CustName = objCustObj.Custname; cust.amount = 25.89D; cust.Companyname = "My company"; cust.Checkin = DateTime.Now; cust.Checkout = DateTime.Now; xy.Customers.InsertOnSubmit(cust); xy.SubmitChanges(); } } }
Any help would be appreciated. Thanks.try using this
xy.InsertOnSubmit(cust);
instead ofxy.Customers.InsertOnSubmit(cust);
hope this may work... -
I am doing an insert opertion here in this code but when I opened table it shows blank rows.
namespace DAL { public class DALCustomerEntery { NorthwindMapping.NorthwindDataContext xy = new NorthwindMapping.NorthwindDataContext(); public void InsertData(Customer objCustObj) //this object is coming from BOL { NorthwindMapping.Customer cust= new NorthwindMapping.Customer(); cust.CustName = objCustObj.Custname; cust.amount = 25.89D; cust.Companyname = "My company"; cust.Checkin = DateTime.Now; cust.Checkout = DateTime.Now; xy.Customers.InsertOnSubmit(cust); xy.SubmitChanges(); } } }
Any help would be appreciated. Thanks.change xy.customers.insertonsubmit(cust); to xy.insertonsubmit(cust)