Dear Experts
How to find the Records into datagridview using from Textbox in windows application C#. Back End SQL server2005.
I am having 5 fields(Date,Name,Address,etc..) in database. All that fields are binding with data grid in Form1 and also one text box. when i am load the Form1 all fields are displaying in datagrid view. everything going good so far.
Now, I want type the some text into textbox( private void txtdate_TextChanged(object sender, EventArgs e) ) like type date (ex:05-05-2014), the date will be highlighting in Data Grid view where every it has placed.
Thanks in Advance
Sreeni
Loading
Dipankar BiswasPosted Jul 31, 2014, 4:12 AM
Riddhi ValechaPosted Jul 31, 2014, 3:19 AM
Placing only 1 textbox for searching records from gridview is a wrong practice.
Right now, say you have 5 fields - Date, Name, Address, Salary, BankName.
Now, in your backend (say SQL Server), make a dynamic search query.
Your stored procedure will look like - (I am explaining for 2 variables - Date and Name.)
-----------Stored Procedure----------
@Date datetime = null,
@Name varchar(50) = null
Begin
declare @SQLQUERY as nvarchar(max)
@SQLQUERY = 'select * from TableName where 1=1'
If @Date is not null then
@SQLQUERY = @SQLQUERY + 'and TableName.Date = '''+@Date+''''
If @Name is not null then
@SQLQUERY = @SQLQUERY + 'and TableName.Name = '''+@Name+''''
exec @SQLQUERY
-------------End Of Stored Procedure--------------
For Front End -
Take 5 textboxes.
Make a method in Code File.
ANd Call the procedure.
------
Font-End is a easy task.
Please send your project if you can.
I will make changes in that and send it back.
Hope this helps.