Click here to Skip to main content
Sign Up to vote bad
good
See more: C#Windows
someone pls give me a related sample code
Posted 23 May '12 - 1:34


4 solutions

You need to try first by yourself.
 
Follow these steps:
1. Design a form where you place few search parameters. For example, here for you - from date, to date calendars & a textbox for ID.
2. Now, place a search button as the trigger control of the search. On click event of search button you would be writing your logic.
3. In search button click, get the search parameters (like the id in textbox, dates in calendar), use it, form a query, put it in database as Stored Procedure and execute on database
4. Get the SP result back in a datatable and bind it to a grid or any other appropriate control based on your needs
5. For now, Datagrid will display the retrieved result.

Done!
  Permalink  
Comments
Member 8983639 - 23 May '12 - 22:47
how to send textbox data into stored procedure in general in sql queries we wrtie a query string but here the case is different its a stored procedure so how to do
Hi ,
Check this
        protected void Page_Load(object sender, EventArgs e)
    {
 
        if (!IsPostBack)
        {
            //Bring all Data in First load
            Bind();
        }
        else
        {
            if (ViewState["dt"] != null)
            {
                dt = (DataTable)ViewState["dt"];
                GridView1.DataSource = dt;
                GridView1.DataBind();
            }
        }
         
    }
    DataTable dt = new DataTable();
    DataTable search(int id)
    {
        using (
              SqlConnection con =
                  new SqlConnection(ConfigurationManager.ConnectionStrings["testConnectionString"].ConnectionString))
        {
 
            SqlCommand cmd = new SqlCommand("usp_Search_All", con);
 
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("id", id);
            SqlDataAdapter adpt = new SqlDataAdapter(cmd);
            adpt.Fill(dt);
            GridView1.DataSource = dt;
            GridView1.DataBind();
            cmd.Dispose();
            return dt;
 
        }
    }
    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        GridView1.PageIndex = e.NewPageIndex;
        GridView1.DataSource =(DataTable)ViewState["dt"];
        GridView1.DataBind();
        
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        dt = search(Convert.ToInt32(TextBox1.Text));
        ViewState.Add("dt", dt);
    }
    void Bind()
    {
        using (
              SqlConnection con =
                  new SqlConnection(ConfigurationManager.ConnectionStrings["testConnectionString"].ConnectionString))
        {
 
            SqlCommand cmd = new SqlCommand("usp_Select_All", con);
            cmd.CommandType = CommandType.StoredProcedure;
            SqlDataAdapter adpt = new SqlDataAdapter(cmd);
            adpt.Fill(dt);
            GridView1.DataSource = dt;
            GridView1.DataBind();
            cmd.Dispose();
    
 
        }
    }
<div>
        
 
<asp:GridView ID="GridView1" runat="server" AllowPaging="True"
            onpageindexchanging="GridView1_PageIndexChanging" PageSize="5">
        </asp:GridView>
        <br />
        <br />
        <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
&nbsp;
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
    </div>
 
Best Regards
M.Mitwalli
  Permalink  
Comments
Member 8983639 - 23 May '12 - 22:44
thanks alot and lot so much im new to .net and all one doubt is this same for windows application also?
Member 8983639 - 23 May '12 - 22:50
i want to get data from stored procedure....
Mohamed Mitwalli - 24 May '12 - 1:21
Check the Solution it's already updated
frankly it's a great job , but i want to know the code about the stored procedure that we created
  Permalink  
Can you elaborate what you mean from stored procedure? Do you want to do filtering in stored procedures? Or do you have filtered data and want to fill data grid view with the filtered data?
  Permalink  
Comments
Member 8983639 - 23 May '12 - 8:00
i want to filter the datagridview when user search an value in textbox where my data is present in stored procedure i have 3 parameters in it 1) from date 2)to date 3) Supervisor ID. now i need to filter the grid view from searchbox(textbox)
Member 8983639 - 23 May '12 - 8:00
pls help me with sample code

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Sergey Alexandrovich Kryukov 425
1 OriginalGriff 315
2 Slacker007 240
3 Dave Kreskowiak 212
4 Aarti Meswania 210
0 Sergey Alexandrovich Kryukov 8,893
1 OriginalGriff 7,134
2 CPallini 3,678
3 Rohan Leuva 3,036
4 Maciej Los 2,428


Advertise | Privacy | Mobile
Web01 | 2.6.130516.1 | Last Updated 14 Nov 2012
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid