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...

Any help plz??

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();

dt.Columns.Add("Column1");
dt.Columns.Add("Column1");

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)
{
   dt.Rows.Add(o.column1,
                o.column2);
}

datagrid1.DataSource = dt;
datagrid1.BindData();

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.

i found a solution thanks for the advice :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.