健美运动员的肚子:怎样在DELPHI 三层中,对数据进行添加,修改,删除?

来源:百度文库 编辑:高考问答 时间:2024/05/09 10:10:14

任何程序的三层都是差不多的

一般三层的结构是:
1:数据访问层
2:业务逻辑层
3:表示层

你去下点代码看要好点

一般你的数据访问层写你怎么访问数据库,业务逻辑就是你的一些逻辑,包括对库的操作(如果对库操作,就要调用数据访问层)比如:在业务逻辑层写一个函数,我用的C#语法,

数据访问层:
public string runsql_p(SqlParameter[] param,string strsql)
{
SqlConnection oconnection = new SqlConnection(connstr);
oconnection.Open();
SqlCommand ocommand = new SqlCommand(strsql);
ocommand.CommandType = CommandType.Text;
ocommand.Connection = oconnection;
if (ocommand.Parameters.Count==0)
{
foreach (SqlParameter p in param)
{
ocommand.Parameters.Add(p);
}
}
try
{
ocommand.ExecuteNonQuery();
oconnection.Close();
oconnection.Dispose();
ocommand.Dispose();
return("ok");
}
catch (InvalidCastException ex)
{
oconnection.Close();
oconnection.Dispose();
ocommand.Dispose();
return(ex.Message.ToString());
}
}

逻辑层:

static Access.Visit vst=new PingGu.Access.Visit();

public static void PartnerDelete(string id,string database)
{
string strsql="delete gdqk where id=@id";
SqlParameter[] param=new SqlParameter[1];
param[0]=new SqlParameter("@id",id);
vst.runsql_p(param,strsql);

}

这个vst.runsql_p是数据访问层的,在表示层如果要做删除操作,只需要调用逻辑层的这个函数就可以了