简体   繁体   中英

How to bind data from database to a specific DatagridView Column Name using vb.net

I would like to bind different queries for a long set of columns in datagridview that has been set already during the formload, eg:

With dgvGrid

.Columns(0).Name = "Dept Code"
        .Columns(1).Name = "Emp ID"
        .Columns(2).Name = "Pay Date"
        .Columns(3).Name = "Pay Type"
        .Columns(4).Name = "Regular Days"
        .Columns(5).Name = "Holidays"
        .Columns(6).Name = "Tardy Hours"
        .Columns(7).Name = "Tardy Amount"
        .Columns(8).Name = "Basic Pay"
        .Columns(9).Name = "Regular Wage"
        .Columns(10).Name = "Reg OT Hrs"
        .Columns(11).Name = "Reg OT Amt"
        .Columns(12).Name = "Rest OT Hrs"
        .Columns(13).Name = "Rest OT Amt"
        .Columns(14).Name = "Legal OT Hrs"
        .Columns(15).Name = "Legal OT Amt"

there are still more of it. The data needed for those columns is coming from a different table.

If I understand your question and you need to make queries on you data exist in the grid view! The Best way to do is using DataView and bind it to the DataGridView and make your queries using the RowFilter in DataView...

DataView dvTemp = new DataView(dsTemp.Tables[0]); dataridviewEmployee.DataSource = dvTemp;

On your Query:

dvTemp.RowFilter = "Emp_ID <= 100 AND Regular_Wage > 2000";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM