Click here to Skip to main content
11,580,000 members (74,265 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# Windows
someone pls give me a related sample code
Posted 23-May-12 1:34am
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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  
v2
Comments
Member 8983639 at 23-May-12 22:47pm
   
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
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

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  
v3
Comments
Member 8983639 at 23-May-12 22:44pm
   
thanks alot and lot so much im new to .net and all one doubt is this same for windows application also?
Member 8983639 at 23-May-12 22:50pm
   
i want to get data from stored procedure....
Mohamed Mitwalli at 24-May-12 1:21am
   
Check the Solution it's already updated
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

frankly it's a great job , but i want to know the code about the stored procedure that we created
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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 at 23-May-12 8:00am
   
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 at 23-May-12 8:00am
   
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
0 OriginalGriff 218
1 Frankie-C 170
2 Abhinav S 65
3 Sergey Alexandrovich Kryukov 49
4 Dave Kreskowiak 45
0 OriginalGriff 1,088
1 Sergey Alexandrovich Kryukov 750
2 Abhinav S 638
3 Suvendu Shekhar Giri 433
4 F-ES Sitecore 420


Advertise | Privacy | Mobile
Web04 | 2.8.150603.1 | Last Updated 14 Nov 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100