我想知道如何将这个数据访问层代码放在一个类文件中,并在这个 default.aspx 中为受保护的 void submit 调用函数。我有一个存储过程,我正在检索值并将其传递到这里,现在我想将 DAL 放在单独的文件中
问问题
386 次
1 回答
2
make a new Class
file, for instance
public class ServiceClass
{
//paste your method inside this class, for example:
public static string returnSomething(string parameter1, string parameter2 /*more parameters here*/)
{
return parameter1 + " " + parameter2;
}
}
You basically have to paste the code you have in your button_click
event right now, just make sure that you pass all the parameters that you need for the code to work.
when you have this class, you can call the class' method in your button click event:
protected void submit(object sender, EventArgs e)
{
string result = ServiceClass.returnSomething();
}
i made it a static method, so you dont need to instantiate the ServiceClass
in order to access the returnSomething()
method.
于 2012-07-20T21:56:19.220 回答