.NET程序中使用存储过程

public string Login(string userName, string password) {

string customerID;

// params to stored proc

Database data = new Database();

SqlParameter[] prams = {

data.MakeInParam("@username", SqlDbType.VarChar, 25, password),

data.MakeInParam("@password", SqlDbType.VarChar, 25, userName),

data.MakeOutParam("@CustomerID", SqlDbType.VarChar, 25)

};

// create data object and params

data.RunProc("upAccountLogin", prams); // run the stored procedure

customerID = (string) prams[2].Value; // get the output param value

// if the customer id is an empty string, then the login failed

if (customerID == string.Empty)

return null;

else

return customerID;

}

这段代码是Customer类的Login方法,它是通过将用户输入的用户名userName和密码password做为输入参数传递给存储过程upAccountLogin的,这个存储过程完成在Sigon用户帐号表里面查找该用户是否合法,最后返回一个字符串的用户ID值。在这里没有使用SQL查询语句,很好的分离了逻辑。具体的数据库访问是通过Database来完成的

posted @ 2009-04-21 11:51  斑点海豚---寂静的港湾  阅读(152)  评论(0编辑  收藏  举报