Please bear with me while i explain my question. I think it will make more sense. Thank you:
I have a table in SQL server 2005 with three columns CustomerID (integer, identity), Name(varchar(50) and Address(varchar(50). I created four stored procedures for the table (CustomerSelect, CustomerInsert, CustomerDelete and CustomerUpdate).
In VS 2008, i created a connection string to the table using Settings.settings. I then created a Data Access Class with the following code to enable me sellect and view a customer in the database:
Code:public class CustomerDAL { private string connectionString = Properties.Settings.Default.BranchAppConnString; public Branch SelectCustomer(int ID) { SqlConnection conn = new SqlConnection(connectionString); SqlCommand cmd = new SqlCommand("CustomerSelect", conn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@CustomerID", ID); try { conn.Open(); SqlDataReader reader = cmd.ExecuteReader(CommandBehavior.SingleRow); if (reader.Read()) { Customer customer = new Customr((string)reader["CustomerName"], (string)reader["address"]); return (customer); } else { return null; } } finally { conn.Close(); } }
Now i created Data Class (Customer) with the properties for the Customer Entity. I also exposed the CustomerDAL class to the application using a partial class. Now this works just fine. I can insert a Customer ID in a text box and click a botton to view the customer.
My question is: How can i use the same pattern to insert, delete and update the customer table via the corresponding stored procedures?
Please help me with this. Thanks


Reply With Quote

Bookmarks