简体   繁体   中英

how display record from table to gridview on page load and also search record for particular fields using textbox vb.net?

My database : table1

ID             FIRSTNAME              AGE
1              Sumit                  22
2              Sanjeev                23

i have gridview 1 and textbox1 and button1

i want when pages load the gridview displays the all records from table1 and also ...ii wanna search record for firstname by typing sumit in textbox1 and click on button1 then in gridview the record of sumit will be shown ..by default gridview display alll records from table1

How to do this ?

My Selct Query is below : but it doesnot display all record ...but it can display record if you search for a particular record ...

SELECT a1_admins.EmployeeId, a1_admins.Firstname, a1_admins.Lastname, a1_admins.Email
, a1_admins.City, a1_admins.State, a1_admins.Country, aspnet_Membership.LastLoginDate
, aspnet_Membership.CreateDate, a1_admins.Password, a1_admins.pan_no, a1_admins.Contactno
, a1_admins.Address 
FROM a1_admins 
INNER JOIN aspnet_Membership 
ON a1_admins.UserId = aspnet_Membership.UserId 
WHERE (a1_admins.EmployeeId LIKE N'%' + @EmployeeId + N'%') 
    OR (a1_admins.City LIKE N'%' + @City + N'%') 
    OR (a1_admins.State LIKE N'%' + @State + N'%') 
    OR (a1_admins.Country LIKE N'%' + @Country + N'%')

I assume the variables are set to NULL when not filtered? That would cause the LIKEs to fail, since X LIKE NULL cannot be true.

SELECT
  a1_admins.EmployeeId, a1_admins.Firstname, a1_admins.Lastname, a1_admins.Email, 
  a1_admins.City, a1_admins.State, a1_admins.Country, aspnet_Membership.LastLoginDate, 
  aspnet_Membership.CreateDate, a1_admins.Password, a1_admins.pan_no, a1_admins.Contactno, a1_admins.Address 
FROM a1_admins 
INNER JOIN aspnet_Membership ON a1_admins.UserId = aspnet_Membership.UserId 
WHERE (a1_admins.EmployeeId LIKE N'%' + @EmployeeId + N'%') 
   OR (a1_admins.City LIKE N'%' + @City + N'%') 
   OR (a1_admins.State LIKE N'%' + @State + N'%') 
   OR (a1_admins.Country LIKE N'%' + @Country + N'%')
   OR (Coalesce(@employeeid,@city,@state,@country) is null)

You can add the last clause, which shows everything if all of the filters are not set.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM