Posts

Showing posts from September, 2012

Adding Rows Dynamically to GridView in asp.net

Dynamically we can rows to gridview in asp.net please follow below code

 protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {

           DataTable dt = new DataTable();

            DataRow dr = null;
            dt.Columns.Add(new DataColumn("Column Name", typeof(DataType)));
            dt.Columns.Add(new DataColumn(" Column Name ", typeof( DataType )));

            dt.Columns.Add(new DataColumn(" Column Name ", typeof( DataType )));

            dt.Columns.Add(new DataColumn(" Column Name ", typeof( DataType )));

            dr = dt.NewRow();
            GridBind();
}
}



private void GridBind()
    {
        DataSet ds = new DataSet();
        SqlConnection con = new SqlConnection("Connection string");
        SqlDataAdapter dap = new SqlDataAdapter("Store Procedure", con);
        dap.SelectCommand.CommandType = CommandType.StoredProcedure;
        dap.Fill(ds);
        grd.DataSourc…

Data bind Dropdownlist in asp.net

Image

Data Base connection in ado.net

Image
A SqlConnection is an object, just like any other C# object.  Most of the time, you just declare and instantiate the SqlConnection.
Ado.net  will contain following steps.

Instantiate the SqlConnection.Open the connection.Pass the connection to other ADO.NET objects.Perform database operations with the other ADO.NET objects.Close the connection.

using (SqlConnection connection = newSqlConnection(connectionString))        {            // Create the Command and Parameter objects.SqlCommand command = new SqlCommand("Employee_Insert", connection);            command.Parameters.AddWithValue("@CityName", txtCity.Text);            command.Parameters.AddWithValue("@Name", txtName.Text);            command.CommandType = CommandType.StoredProcedure;            try{                connection.Open();                command.ExecuteNonQuery();            }            catch (SqlException ex){                throw ex;            }            catch (Exception ex){���������…