bonjour je travaille dans une application qui est reliée avec access
j ai un probleme au niveau d affichage des données dans datagridview et voila les etapes que j ai utilisé:
CLASS CONNECTION
DATACCESS:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40 public class connection dim maconnection as oledbconnection = new oledbconnection dim adapter as oledbdataadapter = new oledbdataadapter dim chaineconnection as string = "provider=microsoft.jet.oledb.4.0;" & _ "data source=|datadirectory|\cyberdb.mdb" & ";" & _ "persist security info=false" public function select_datatable(byval cmd as oledbcommand) as datatable dim dt as new datatable try maconnection.close() maconnection.connectionstring = chaineconnection maconnection.open() if maconnection.state = connectionstate.open then cmd.connection = maconnection adapter.selectcommand = cmd ' dt = new datatable adapter.fill(dt) else msgbox("connexion failed...") end if catch ex as exception msgbox(ex.message & " select_datatable") end try return dt end function public function mise_a_jour(byval cmd as oledbcommand) as integer dim i as integer maconnection.close() maconnection.connectionstring = chaineconnection maconnection.open() cmd.connection = maconnection i = cmd.executenonquery() return i end function end class
et dans la class ou se trouve le datagrid j ai mis ce code:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 imports system.data.oledb public class dataaccess dim con as new connection public function listdesplaystations() as datatable dim cd as new oledbcommand dim dt as new datatable try cd.commandtext = "select * from playstation" dt = con.select_datatable(cd) catch ex as exception msgbox(ex.message & " liste des playstation") end try return dt end function end class
Merci de vous me donner la sollution
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9 imports system.windows.forms public class playstation dim dacces as new dataaccess private sub playstation_load(byval sender as system.object, byval e as system.eventargs) handles mybase.load playstationdatagridview.datasource = dacces.listdesplaystations end sub end class
Partager