Could anyone please show me how to display data in a datagrid when I log in as a user into my application??

The after a successful login a form opens. That form displays data and then there's an option where the user can open a form called "Time Management". In that form I want only the table in my "Logbookdatabase" that matches the name of the the logged in person to be displayed in my datagrid.

Note that my tables are named after every user, for example if the table's name is User1 then only User1's data will be shown in the datagrid.

Any help would be appreciated...

7 Years
Discussion Span
Last Post by TheDocterd


DataGrids use the DataSource property to assign a set of data to show in the actual grid. I do not use DataGrids too often any more, you may want to look into using gridviews, but the basic way that I used to do this was to create a DataTable, add the columns I wanted and set the the row values. Then bind the data. I generally use Linq to create a list of the data from the table desired. So,

DataTable dt = new DataTable();


List<objects> list1 = methodToGetList();//this is where you can use logic to decide 
//what table to use to fill the list;

foreach(object o in list1)

datagrid1.DataSource = dt;

You can use the supplied log in information to decide what table to query to populate the list of data. Bear in mind, the columns in the datatable have to be names the same as the columns on the DataGrid in order for this to work.

Hope that helps some.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.