This Data Link Layer returns Objects of the Classes. I tried to give a generic look so tht it can be used in any project. It will require small changes.
using System;
using System.Data;
//using System.Configuration;
using System.Linq;
//using System.Web;
//using System.Xml.Linq;
using System.Data.SqlClient;
using McAfee.Utilities.DatabaseHelper;
using System.Collections.Generic;
namespace Blog.BO
{
///
/// Summary description for Database_Connection
///
public class Database_Connection
{
private string sql_Connection_String = new ConnectionString().GetConnectionString();
public List
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Class Logic
public UserObject Forobject(SqlDataReader reader, List names)//(string name, object val)
{
UserObject new_User = new UserObject();
foreach (string name in names)
{
switch (name)
{
case "userId": new_User.UserId = (string)reader[name];
break;
case "username": new_User.UserName = (string)reader[name];
break;
}
}
return new_User;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Class
public class UserObject
{
public string UserName { get; set; }
public string UserId { get; set; }
public string Password { get; set; }
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Example which uses this:
public List GetData()
{
int input_Size = 10;
SqlParameter[] sql_Param= null;
List dataResult = new Database_Connection().Exec_Select_Query(Stored_Procedure_Names.GetUsersInfo, sql_Param, object_Type, input_Size);//(typeof(ArticleObject), sqlQuery, input_Size, article.ArticleId.ToString());
if (dataResult == null) return null;
List users = new List(2);
if (dataResult == null) return null;
foreach (Object obj in dataResult)
{
users.Add((UserObject)obj);
}
return users;
//List objects;
//string sqlQuery = "select userId,username from userinfo where userId <> 'admin'";
//int input_Size = 10;
//objects = new Database_Connection().Connection_Select_Database(typeof(UserObject), sqlQuery, input_Size);
}
No comments:
Post a Comment