Click here to Skip to main content
15,902,634 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Writting the search code by name and\or date and data display in datagrid
by c# and sql server.
Posted
Updated 1-Oct-11 2:17am
v2
Comments
RaisKazi 1-Oct-11 7:58am    
Need more information.

Try this steps.

1. Make connection to Sql
2. Fill dataset
3. make dataview
4. bind it to datagrid
5. Give input option in UI (c#) for name/date filter
6. pass the value to dataview and use filter as below
SQL
dv.Table.Select("name = "+ txtName.Text)

7. Bind the result to datagrid
 
Share this answer
 
Hope this helps

try
           {
               SqlConnection oConn = new SqlConnection();
               oConn.ConnectionString = "Data Source=EXPERIENCE;database=Test;user=sa;password=admin1990";
               oConn.Open();

               string strDate=String.Format("{0:dd/MMM/yyyy}", dtpDate.Value);
               string strSQL = "Select * from attendance where CheckIn='" + strDate + "'";

               if (txtName.Text.Trim().Length != 0)
                   strSQL = strSQL + " and name like '%"+ txtName.Text +" %'";


               SqlCommand oCmd = new SqlCommand(strSQL,oConn);
               var da = new SqlDataAdapter(oCmd);
               var nwSet = new DataSet();
               da.Fill(nwSet);

               dg.DataSource = nwSet.Tables[0].DefaultView;

               MessageBox.Show ("Sucess");
           }
           catch (Exception ex)
           {

               MessageBox.Show(ex.Message);
           }
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900