Sunday, August 26, 2012

C# to SQL Server's Stored Procedure

this time, I will post about how access SP in SQL Server and take it to our application like Data Grid View or Repeater..

For example, let say that I want to take all the names from the database and put them in the List of String..

public List getAllUserName()
        {
            string spName = "spr_getAllName";

            List listUser = new List();
            String name= null;

            using (SqlDataReader sqlDataReader = SqlHelper.ExecuteReader(SqlConnection, CommandType.StoredProcedure, spName))
            {
                if (sqlDataReader.HasRows)
                {
                    while (sqlDataReader.Read())
                    {
                        name= new String();
                        name= sqlDataReader["Name"].ToString();
                        listUser.Add(name);
                    }
                }
            }
            return listUser;
        }

ASP C# .NET Master Pages

Recently I encounter a few problems in my website. I use Master Page in order not to use same tools in every page. the problem is that I want to use 1 single page but using 2 Master Pages. how a single page can use 2 Master Pages?

So this is the answer.

private void Page_PreInit(object sender, EventArgs e)
{
    if (Session["userID"].ToString() != null)
   {
         this.MasterPageFile = MasterPage2.master"; //use master page number 2 when user login
   }
   else
    {





          this.MasterPageFile = MasterPage1.master";  //use master page number 1 before user login
    }
}