Tuesday, April 28, 2015

DataGridView Implementation with DataSet

DataGridView Implementation with DataSet

SqlConnection connection = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["studentConnectionString"].ConnectionString);
            string sql = "SELECT * FROM student";
            SqlDataAdapter dataadapter = new SqlDataAdapter(sql, connection);
           
            DataSet ds = new DataSet();
            connection.Open();
            dataadapter.Fill(ds, "student");
            connection.Close();
            dataGridView1.DataSource = ds;
           // dataGridView1.DataMember = "student"; //DataMember -- if the DataSet content More than one table then binding the particular table with grid we use this 
            dataGridView1.DataBind();

Visual studio 2013 keybord shortcart

Wednesday, April 22, 2015

Insert in DB C# Dot Net

Please find the following code for connecting with DB

SqlConnection connection = new SqlConnection("Data Source=MACK;Initial Catalog=student;User ID=sa;Password=sourav321");
            SqlCommand command = new SqlCommand();
            command.Connection = connection;

            command.CommandText = "insert into student(id, username, password, name, email) values(@id, @uname, @password, @name, @email)";
            command.Parameters.Add("@uname", UserName.Text);
            command.Parameters.Add("@password", Password.Text);
            command.Parameters.Add("@name", Name.Text);
            command.Parameters.Add("@email", Email.Text);
            command.Parameters.Add("@id", Guid.NewGuid().ToString());
            connection.Open();
            command.ExecuteNonQuery();
            connection.Close();

ASP Dot Net page life Cycle

Page_PreInit -> Page_Init -> Page_InitComplete
Page_PreLoad -> Page_Load
Page_PreRender -> Page_Render