***
namespace Competition.DataLayer
{
using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
public class DataManager
{
public DataManager()
{
}
private SqlConnection OpenConnection()
{
SqlConnection oCon = new SqlConnection("competition_str");
oCon.Open();
return oCon;
}
private void CloseConnection(SqlConnection oCon)
{
if (oCon != null)
{
oCon.Close();
oCon.Dispose();
}
}
public object ExecuteNonQuery(string sSQLText, SqlParameter [] oParam)
{
SqlConnection oCn = OpenConnection();
SqlCommand cmd = new SqlCommand();//sSQLText, oCn);
cmd.Connection = oCn;
cmd.CommandText = sSQLText;
if (oParam != null && oParam.Length > 0)
{
foreach(SqlParameter oOneParameter in oParam)
{
cmd.Parameters.Add(oOneParameter);
}
}
object oRetVal = cmd.ExecuteNonQuery();
CloseConnection(oCn);
return oRetVal;
}
}
}
业务逻辑层代码-
namespace Competition.BusinessLogicLayer
{
using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Competition.DataLayer;
#region "variables"
public class Candidate
{
//#region "variables"
private string sName;
private string sAddress;
private string sState;
private string sCity;
private string sFName;
private float fWeight;
private float fHight;
private string sQualification;
private string sAssoclubName;
private string sSeniorName;
private string sNoc;
private string sComments;
private DateTime dtDob;
private int iAddedBYId;
public Candidate()
{
}
public string Name
{
get { return sName; }
set { sName = value; }
}
public string Address
{
get { return sAddress; }
set { sAddress = value; }
}
public string State
{
get { return sState; }
set { sState = value; }
}
public string City
{
get { return sCity; }
set { sCity = value; }
}
public string FName
{
get { return sFName; }
set { sFName = value; }
}
public float Weight
{
get { return fWeight; }
set { fWeight = value; }
}
public float Height
{
get { return fHight; }
set { fHight = value; }
}
public string Qualification
{
get { return sQualification; }
set { sQualification = value; }
}
public string AssoclubName
{
get { return sAssoclubName; }
set { sAssoclubName = value; }
}
public string SeniorName
{
get { return sSeniorName; }
set { sSeniorName = value; }
}
public string IsNoc
{
get { return sNoc; }
set { sNoc = value; }
}
public string Comments
{
get { return sComments; }
set { sComments = value; }
}
public DateTime Dob
{
get { return dtDob; }
set { dtDob = value; }
}
public int AddedBYId
{
get { return iAddedBYId; }
set { iAddedBYId = value; }
}
#region "Function"
public int InsertCandidate()
{
SqlParameter[] oParam =
{
new SqlParameter("@prm_name",sName),
new SqlParameter("@prm_dob",dtDob),
new SqlParameter("@prm_fname",sFName),
new SqlParameter("@prm_state",sState),
new SqlParameter("@prm_city",sCity),
new SqlParameter("@prm_address",sAddress),
new SqlParameter("@prm_weight",fWeight),
new SqlParameter("@prm_height",fHight),
new SqlParameter("@prm_qualification",sQualification),
new SqlParameter("@prm_associateclubname",sAssoclubName),
new SqlParameter("@prm_seniorname",sSeniorName),
new SqlParameter("@prm_noc ",sNoc),
new SqlParameter(" @prm_comments",sComments),
new SqlParameter("@prm_addedbyid",iAddedBYId)
};
int iSuccessful = DataManager.ExecuteNonQuery("p_cand_insert", oParam);
}
#endregion
}
#endregion
}`