2
DateTime startDate = DateTime.ParseExact(txtstart.Text, "MM/dd/yyyy", null);
DateTime endDate = DateTime.ParseExact(txtend.Text, "MM/dd/yyyy", null);

string n1 = DropDownList2.SelectedItem.Text;
       if (DropDownList1.SelectedItem.Text == "Membership")// here you can add selectedindex as well
        {
          SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ProjectConnectionString"].ToString());
          con.Open();
          SqlDataAdapter adapter = new SqlDataAdapter("select * from Membership_det where updateDate  between @Start and @End and FID ="+n1+"", con);
          adapter.SelectCommand.Parameters.Add("@Start", SqlDbType.Date).Value = startDate;
          adapter.SelectCommand.Parameters.Add("@End", SqlDbType.Date).Value = endDate;
        }

…….. …….. Above is a part of a code to display the data in the grid view.I am displaying * from Membership_det and also need to display faculty name from other table…how to add the query with the above query..displaying * from membership _det table and faculty name from other table

FID MembNo  MembType    Validity    Remarks UpdateDate
100 23  basn    6   dgag    9/5/2013 12:00:00 AM
200 566 basn    6   adhu    9/6/2013 12:00:00 AM

In this table i need to add Faculty name..it should be fetched from other table..

coder
  • 13,002
  • 31
  • 112
  • 214
  • You can use joins / subqueries. Show us the table structures so that we can provide you the detail solution. – Manoj Sep 11 '13 at 06:19
  • Learn about subqueries and table joins to retrive related data from different tables. Use [this](http://stackoverflow.com/a/406333/2281515) – Nisha Sep 11 '13 at 06:33

4 Answers4

1

You can JOIN tables as below. Change the Relationship and the column names based on your tables. it is better if you can use parameter for FID as well

SELECT m.*, f.Name
FROM Membership_det m
INNER JOIN faculty f
ON m.FID = f.FID
WHERE m.updateDate  between @Start and @End and m.FID =@FID ;
Damith
  • 62,401
  • 13
  • 102
  • 153
1

You can join Memberhip_det table with the other table to retrieve faculty_name. But these two tables should have a common connecting field or primary and foreign keys.

Also try using stored procedures rather than inline queries

Nisha
  • 1,379
  • 16
  • 28
0

Try to use union for your two sql select statements

UNION The UNION command is used to select related information from two tables, much like the JOIN command. However, when using the UNION command all selected columns need to be of the same data type. With UNION, only distinct values are selected.

coder
  • 13,002
  • 31
  • 112
  • 214
0

Make foreign key relation ship to FID column on faculty table and change your query as follows

select Membership_det.MembNo, Membership_det.MembType,Membership_det.Validity,Membership_det.Remarks,Membership_det.UpdateDate,faculty.facultyname FROM Membership_det INNER JOIN faculty ON Membership_det.FID = faculty.FID
WHERE Membership_det.updateDate  between @Start and @End and Membership_det.FID =@FID ;
user2561316
  • 394
  • 3
  • 7