vb.net - how to look up a a value from another datatable and display it in an unbound column of a bound datagridview -
i'm sorry, tried search answer i'm having hard time translating examples i've found own scenario.
i have ms access database has "employees" table following columns:
"employee id", "name", "middle", "last", "hire date", "fired date".
another table "work" has columns:
"date", "employee id", "activity", "hours worked", "department", "shift", "equipment used",
a datagridview bound "work" table. call fillbydate() query made query editor @ design time entries specific date loaded.
i create unbound column display name (name, middle, , last) of employee "employees table" using employee id find it.
i'm new coding vb.net, might reason why don't understand or find right examples. appreciate sample code , comments each step see how things working.
just fyi i'm reading couple of coding books: practical database programming vb.net, visual basic 2010, masterig ms visual basic 2010
thank in advance.
a better way create sql query join tables based on employee id field , filter data based on date field. datagridview binded datatable filled based on sql query.
sample code :
dim filterstr1 string = "03/01/2013" dim dbpathstr1 string = "c:\db1.mdb" private sub button1_click(sender system.object, e system.eventargs) handles button1.click dim sqlconnstr1 string = "provider=microsoft.jet.oledb.4.0;data source=" & dbpathstr1 & ";" dim sqlstr1 string = <sql> select w.[date] ,w.[employee id] ,w.[activity] ,w.[hours worked] ,w.[department] ,w.[shift] ,w.[equipment used] ,e.[name] ,e.[middle] ,e.[last] [work] w inner join [employees] e on w.[employee id] = e.[employee id] w.[date] = #<%= filterstr1 %># </sql>.value dim oledbadap1 new oledbdataadapter(sqlstr1, sqlconnstr1) dim sqldtable1 new datatable oledbadap1.fill(sqldtable1) datagridview1.datasource = sqldtable1 oledbadap1.dispose() end sub
to use code need change value of variable dbpathstr1
path of ms access database , set date value filterstr1
variable.
edit
the value of filterstr1
variable can assigned using datetimepicker control. need add datetimepicker control on form , add following code.
private sub datetimepicker1_valuechanged(sender system.object, e system.eventargs) handles datetimepicker1.valuechanged filterstr1 = datetimepicker1.value.tostring("dd/mm/yyyy") end sub
Comments
Post a Comment