Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save joshi-kumar/60744f164b9dd5a27f7e0b3c268a09c9 to your computer and use it in GitHub Desktop.
Save joshi-kumar/60744f164b9dd5a27f7e0b3c268a09c9 to your computer and use it in GitHub Desktop.
Bind data (Table Record) into Domain using Stored Procudure
Use Old Technique -
------------------------
SqlConnection sqlcon = new SqlConnection(SqlConString);
sqlcon.Open();
SqlCommand cmd = new SqlCommand();
cmd = new SqlCommand("UserRecentRequestList", sqlcon);
cmd.CommandType = CommandType.StoredProcedure;
SqlDataReader reader = null;
reader = cmd.ExecuteReader(CommandBehavior.CloseConnection);
DataTable table = new DataTable();
int numRows = 0;
table.Load(reader);
numRows = table.Rows.Count;
sqlcon.Close();
for (int index = 0; index < numRows; index++)
{
string Id = table.Rows[index]["Id"].ToString();
string CustomerId = table.Rows[index]["CustomerId"].ToString();
string Email = table.Rows[index]["Email"].ToString();
string FirstName = table.Rows[index]["FirstName"].ToString();
string LastName = table.Rows[index]["LastName"].ToString();
string InstituteUserId = table.Rows[index]["InstituteUserId"].ToString();
string AccessType = table.Rows[index]["AccessType"].ToString();
string ClassId = table.Rows[index]["ClassId"].ToString();
string IsActive = table.Rows[index]["IsActive"].ToString();
Convert.ToBoolean(IsActive.Equals(1) ? true : false);
if (!string.IsNullOrEmpty(Total_RecentRequest)) { totalRequest = Convert.ToInt16(Total_RecentRequest); }
}
-----------------------------------------------------------
Bind Data into Domain Using Stored Procedure (Controller)
----------------------------------------------------------
//invoke stored procedure
var userInfo = _dbContext.ExecuteStoredProcedureList<InstituteUser>("UserRecentRequestList");
Here "UserRecentRequestList" is a stored Procedure Name.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment