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.