Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6798055
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:41:02+00:00 2026-05-26T18:41:02+00:00

i have a method that will populate a datatable with the data from a

  • 0

i have a method that will populate a datatable with the data from a sql table which in turn would be used to populate a gridview. Now in the sql table i have a field called “hotel” which contains the “ID” of a hotel which relates to another table called “hotels” with hotel id and name.

Now in my grid view i want to display the hotel name instead of the hotel id. How can i do it.

 public static DataTable GetRequests(string empid)
        {
            DataTable dt = new DataTable();
            string strConnection = ConfigurationManager.AppSettings["connStr"];
            using (SqlConnection connection = new SqlConnection(strConnection))
            {
                connection.Open();
                SqlCommand sqlcmd = new SqlCommand();
                SqlDataAdapter sAdap = new SqlDataAdapter();                
                sqlcmd.Connection = connection;
                sqlcmd.CommandType = System.Data.CommandType.Text;
                sqlcmd.CommandText = "Select request_date,hotel,dining_date,status from requests Where emp_id='" + empid + "'";
                sAdap.SelectCommand = sqlcmd;
                sAdap.Fill(dt);
            }
            return dt;            
        }

This is the method that retrieves the records. The hotel field contains the ID for which i want the name.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T18:41:03+00:00Added an answer on May 26, 2026 at 6:41 pm

    Change to your sql query and thing will work out.

    Let us say ‘Hotel’ which contain hotel id and in the another table ‘HotelDetails which contain the hotel id and hotel name.

    Table structure of Hotel
    HotelId int
    Table structure of HotelDetails
    HotelId int,
    HotelName varchar(10)

    Now you query should be

    SELECT b.HotelName as HotelName, c.request_date as RequestDate,c.dining_date as DiningDate ,c.status as Status FROM Hotel a, HotelDetails b, requests c WHERE a.HotelId = b.HotelId and emp_id='" + empid + "'
    

    In the GridView, your DataFild should be HotelName in order to display Hotel Name

    For instance

    <Columns>
                                                                <asp:TemplateField HeaderText="Slno">
                                                                    <ItemTemplate>
                                                                        <%# Container.DataItemIndex + 1 %>
                                                                    </ItemTemplate>
                                                                    <ControlStyle Width="30px" />
                                                                    <ItemStyle ForeColor="#00846F" Width="30px" />
                                                                </asp:TemplateField>
                                                                <asp:BoundField ControlStyle-Width="90" DataField="HotelName" 
                                                                    HeaderText="Hotel Name" ItemStyle-ForeColor="#00846F" 
                                                                    ItemStyle-Width="30">
                                                                    <ControlStyle Width="30px" />
                                                                    <ItemStyle Width="30px" />
                                                                </asp:BoundField>
                                                                <asp:BoundField ControlStyle-ForeColor="#00846F" ControlStyle-Width="190" 
                                                                    DataField="RequestDate" HeaderText="Request Date" 
                                                                    ItemStyle-ForeColor="#00846F" ItemStyle-Width="100">
                                                                    <ControlStyle Width="100px" />
                                                                    <ItemStyle Width="100px" />
                                                                </asp:BoundField>
                                                                <asp:BoundField ControlStyle-ForeColor="#00846F" ControlStyle-Width="100" 
                                                                    DataField="DiningDate" HeaderText="Dining Date" 
                                                                    ItemStyle-ForeColor="#00846F" ItemStyle-Width="50">
                                                                    <ControlStyle Width="50px" />
                                                                    <ItemStyle Width="50px" />
                                                                </asp:BoundField>
                                                                <asp:BoundField ControlStyle-ForeColor="#00846F" ControlStyle-Width="100" 
                                                                    DataField="Status" HeaderText="Status" 
                                                                    ItemStyle-ForeColor="#00846F" ItemStyle-Width="50">
                                                                    <ControlStyle Width="50px" />
                                                                    <ItemStyle Width="50px" />
                                                                </asp:BoundField>
    
    
    
                                                            </Columns>
    

    If you find it useful, please mark it as your answer else let me know….

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have a COM object implemented with C++/ATL that includes a method which will
I have simple table that has about 80 rows, which I populate dynamically using
I have a method that will receive a string , but before I can
Question Is there a way to have a method that will always run anytime
I have a method that I will use in the following contexts: 1. User
I have some code in method C that will get executed based upon the
We have a static method in a utility class that will download a file
I need a Regex that will match a java method declaration. I have come
I have a method that will return a list of suggested orders. If the
I have a rails app that loads lots of data from some java services.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.