onlDescription
SqlConnection: This ADO.NET class helps to connect database connection, which is in web.config file.
SqlCommand: This ADO.NET class helps call SQL Store procedure or SQL query.
SqlDataReader: This ADO.NET class helps to retrieve/fetch the data from the query.
Code
- public class shoppingCartDetails
- {
- public int cartID
- {
- get;
- set;
- }
- public string description
- {
- get;
- set;
- }
- public shoppingCartDetails GetShoppingDetails()
- {
- shoppingCartDetails sCD = new shoppingCartDetails();
- int pcartID = 0;
- string pdescription = string.Empty;
- string connstring = ConfiguratonManager.ConnectionString["connectionName"];
- using(SqlConnection con = new SqlConnection(connstring))
- {
- using(SqlCommand cmd = new SqlCommand("dbo.SPName", con))
- {
- try
- {
- cmd.CommandType = CommandType.StoredProcedure;
- con.Open();
- SqlDataReader reader = cmd.ExecuteReader();
- if (reader.HasRows)
- {
- while (reader.Read())
- {
- pcartID = Int32.Parse(reader["cartID"].ToString());
- pdescription = reader["description"].ToString();
- }
- break;
- }
- }
- reader.Close();
- sCD.cartID = pcartID;
- sCD.description = pdescription;
- sCD.success = true;
- }
- catch (Exception ex)
- {
- EventLogging.LogEvent("Error getting details", System.Diagnostics.EventLogEntryType.Error);
- sCD.errorMessage = ex.ToString();
- sCD.success = false;
- } finally
- {
- con.Close();
- }
- }
- }
- return sCD;
- }
- }