|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnitTestingWithUnity.Exceptions;
using System.Data.SqlServerCe;
using UnitTestingWithUnity.Properties;
namespace UnitTestingWithUnity.Data
{
public class CustomerDataAccess : ICustomerDataAccess
{
#region ICustomerDataAccess Members
public long CreateCustomer(UnitTestingWithUnity.DTO.Customer customer)
{
SqlCeConnection connection = new SqlCeConnection("Data Source = " + Environment.CurrentDirectory + @"\DataSource\CustomerDB.sdf");
try
{
SqlCeCommand command = new SqlCeCommand("insert into customer (CustomerName, Address) values (@CustomerName, @Address);");
command.Parameters.Add("CustomerName", System.Data.SqlDbType.NVarChar);
command.Parameters.Add("Address", System.Data.SqlDbType.NVarChar);
command.Parameters["CustomerName"].Value = customer.Name;
command.Parameters["Address"].Value = customer.Address;
command.Connection = connection;
connection.Open();
return command.ExecuteNonQuery();
}
catch (Exception ex)
{
throw new DataAccessException("Error while trying to Create.", ex);
}
finally
{
if(connection.State != System.Data.ConnectionState.Closed)
{
connection.Close();
}
}
return -1;
}
#endregion
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.