"If at first you don't succeed; call it version 1.0" :-Unknown

Pages

Sunday, February 27, 2011

Binding Grid Using Store procedure

Hi,
Last day i had given 1 hour class to freshers.On the half of the way i gone through this topic also,anyway i'm not describing what i teach there.Just displaying the code how to achieve it,with a mind will help somebody.



   try
    {
     SqlCommand cmd = new SqlCommand("[SP Name]", new SqlConnection("Server=localhost;Database=Northwind;Trusted_Connection=True;"));
      cmd.CommandType = CommandType.StoredProcedure;
      cmd.Parameters.Add("CustomerID", txtCustID.Text);
      cmd.Connection.Open();
      // Grid Name: Grid
      Grid.DataSource = cmd.ExecuteReader();
      Grid.DataBind();
      cmd.Connection.Close();
      cmd.Connection.Dispose();
    }
    catch (Exception ex)
    {
     lblStatus.Text = ex.Message;
    }


Have a nice day... 'N happy Coding :)

No comments: