views:

39

answers:

2

Here is sample code which I used to update customer table.

public void UpdateCustomer() {

   SAPDB db = new SAPDB();
   SubSonicRepository<Customer> ssr = new SubSonicRepository<Customer>(db);
   Customer customer = new Customer();
   customer.ID = 5;
   customer.CustomerName = "John";
   int val = ssr.Update(customer);

}

Please let me know the way I am following is right or wrong? or Is it a error in SubSonic 3?

A: 

what is your schema?

You might want to load your customer's existing data by doing

Customer c= new Customer(5);
customer.CustomerName = "John";
customer.Save();
Biff MaGriff
I tried your code using MS SQL Server as a back end and it was working fine :( Maybe you do not have your primary key set as an identity? What is the error message you are getting?
Biff MaGriff
A: 

Biff MaGriff -> Thanks for reply. I used MS-SQL. At the moment, I am using as follows,

public void UpdateCustomer() {
Customer cus = new Customer(x => x.ID == 5);
cus.CustomerName = "John"; 
cus.Update(); 
}

Can't I use SubSonicRepository class to update? Because, when I insert the data into the Customer table by using the following method, it's working.

   SAPDB db = new SAPDB();
   SubSonicRepository<Customer> ssr = new SubSonicRepository<Customer>(db);
   Customer c = new Customer();
   c.ID = 5;
   c.CustomerName = "John";
   long insertedID = Convert.ToInt64(ssr.Add(c));
Senthan