Connection a une base de donnée

Résolu
thetoto52 Messages postés 87 Date d'inscription lundi 9 janvier 2006 Statut Membre Dernière intervention 11 novembre 2008 - 28 mars 2006 à 17:14
thetoto52 Messages postés 87 Date d'inscription lundi 9 janvier 2006 Statut Membre Dernière intervention 11 novembre 2008 - 29 mars 2006 à 15:02
Voila j'essais de faire une conection a une base access avec vb.net ma connection est bonne mais la ligne en gras me met une erreur si quelqu'un pouvais me dire ce qui ne vas pas merci.



Dim sql
As
String



Dim macommande
As
New OleDbCommand(sql, connec)



Dim adapt
As
New OleDbDataAdapter



Dim dset
As
New DataSet



Dim bmb
As BindingManagerBase

sql = "select * from Client"


adapt.SelectCommand = macommande


adapt.Fill(dset, "client")


bmb = BindingContext(dset, "Client")

3 réponses

cs_Willi Messages postés 2375 Date d'inscription jeudi 12 juillet 2001 Statut Modérateur Dernière intervention 15 décembre 2018 22
28 mars 2006 à 22:34
Bonsoir,
Tu peux essayer comme ceci, mais quel est le message d'erreur que tu as ?


Dim sql
As
String = "select * from Client"



<STRIKE>Dim macommande
As
New</STRIKE><STRIKE> OleDbCommand(sql, connec)</STRIKE>



Dim adapt
As
New OleDbDataAdapter(sql,connec)



Dim dset
As
New DataSet



Dim bmb
As BindingManagerBase

<STRIKE>adapt.SelectCommand = macommande</STRIKE>


adapt.Fill(dset, "client")


bmb = BindingContext(dset, "Client")
3
thetoto52 Messages postés 87 Date d'inscription lundi 9 janvier 2006 Statut Membre Dernière intervention 11 novembre 2008
29 mars 2006 à 15:02
Public sql As String
Public macommande As OleDbCommand
Public adapt As New OleDbDataAdapter
Public dset As New DataSet
Public bmb As BindingManagerBase

#Region " Code généré par le Concepteur Windows Form "

Public Sub New()
MyBase.New()

'Cet appel est requis par le Concepteur Windows Form.
InitializeComponent()

'Ajoutez une initialisation quelconque après l'appel InitializeComponent()

End Sub

'La méthode substituée Dispose du formulaire pour nettoyer la liste des composants.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Requis par le Concepteur Windows Form
Private components As System.ComponentModel.IContainer

'REMARQUE : la procédure suivante est requise par le Concepteur Windows Form
'Elle peut être modifiée en utilisant le Concepteur Windows Form.
'Ne la modifiez pas en utilisant l'éditeur de code.
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents Label2 As System.Windows.Forms.Label
Friend WithEvents Label3 As System.Windows.Forms.Label
Friend WithEvents Label4 As System.Windows.Forms.Label
Friend WithEvents Label5 As System.Windows.Forms.Label
Friend WithEvents Label6 As System.Windows.Forms.Label
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
Friend WithEvents TextBox2 As System.Windows.Forms.TextBox
Friend WithEvents TextBox3 As System.Windows.Forms.TextBox
Friend WithEvents TextBox4 As System.Windows.Forms.TextBox
Friend WithEvents TextBox5 As System.Windows.Forms.TextBox
Friend WithEvents TextBox6 As System.Windows.Forms.TextBox
Friend WithEvents Button1 As System.Windows.Forms.Button
Friend WithEvents Button2 As System.Windows.Forms.Button
Friend WithEvents Button3 As System.Windows.Forms.Button
Friend WithEvents Button4 As System.Windows.Forms.Button
Friend WithEvents Button5 As System.Windows.Forms.Button
Friend WithEvents Button6 As System.Windows.Forms.Button
Friend WithEvents Button7 As System.Windows.Forms.Button
Friend WithEvents Button8 As System.Windows.Forms.Button
Friend WithEvents Button9 As System.Windows.Forms.Button
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.Label1 = New System.Windows.Forms.Label
Me.Label2 = New System.Windows.Forms.Label
Me.Label3 = New System.Windows.Forms.Label
Me.Label4 = New System.Windows.Forms.Label
Me.Label5 = New System.Windows.Forms.Label
Me.Label6 = New System.Windows.Forms.Label
Me.TextBox1 = New System.Windows.Forms.TextBox
Me.TextBox2 = New System.Windows.Forms.TextBox
Me.TextBox3 = New System.Windows.Forms.TextBox
Me.TextBox4 = New System.Windows.Forms.TextBox
Me.TextBox5 = New System.Windows.Forms.TextBox
Me.TextBox6 = New System.Windows.Forms.TextBox
Me.Button1 = New System.Windows.Forms.Button
Me.Button2 = New System.Windows.Forms.Button
Me.Button3 = New System.Windows.Forms.Button
Me.Button4 = New System.Windows.Forms.Button
Me.Button5 = New System.Windows.Forms.Button
Me.Button6 = New System.Windows.Forms.Button
Me.Button7 = New System.Windows.Forms.Button
Me.Button8 = New System.Windows.Forms.Button
Me.Button9 = New System.Windows.Forms.Button
Me.SuspendLayout()
'
'Label1
'
Me.Label1.Location = New System.Drawing.Point(8, 32)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(88, 24)
Me.Label1.TabIndex = 0
Me.Label1.Text = "Code"
'
'Label2
'
Me.Label2.Location = New System.Drawing.Point(8, 56)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(88, 24)
Me.Label2.TabIndex = 1
Me.Label2.Text = "Nom"
'
'Label3
'
Me.Label3.Location = New System.Drawing.Point(8, 80)
Me.Label3.Name = "Label3"
Me.Label3.Size = New System.Drawing.Size(88, 24)
Me.Label3.TabIndex = 2
Me.Label3.Text = "Adresse"
'
'Label4
'
Me.Label4.Location = New System.Drawing.Point(8, 104)
Me.Label4.Name = "Label4"
Me.Label4.Size = New System.Drawing.Size(88, 24)
Me.Label4.TabIndex = 3
Me.Label4.Text = "CP"
'
'Label5
'
Me.Label5.Location = New System.Drawing.Point(8, 128)
Me.Label5.Name = "Label5"
Me.Label5.Size = New System.Drawing.Size(88, 24)
Me.Label5.TabIndex = 4
Me.Label5.Text = "Ville"
'
'Label6
'
Me.Label6.Location = New System.Drawing.Point(8, 152)
Me.Label6.Name = "Label6"
Me.Label6.Size = New System.Drawing.Size(88, 24)
Me.Label6.TabIndex = 5
Me.Label6.Text = "Tel"
'
'TextBox1
'
Me.TextBox1.Location = New System.Drawing.Point(96, 32)
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.Size = New System.Drawing.Size(184, 20)
Me.TextBox1.TabIndex = 6
Me.TextBox1.Text = "TextBox1"
'
'TextBox2
'
Me.TextBox2.Location = New System.Drawing.Point(96, 56)
Me.TextBox2.Name = "TextBox2"
Me.TextBox2.Size = New System.Drawing.Size(184, 20)
Me.TextBox2.TabIndex = 7
Me.TextBox2.Text = "TextBox2"
'
'TextBox3
'
Me.TextBox3.Location = New System.Drawing.Point(96, 80)
Me.TextBox3.Name = "TextBox3"
Me.TextBox3.Size = New System.Drawing.Size(184, 20)
Me.TextBox3.TabIndex = 8
Me.TextBox3.Text = "TextBox3"
'
'TextBox4
'
Me.TextBox4.Location = New System.Drawing.Point(96, 104)
Me.TextBox4.Name = "TextBox4"
Me.TextBox4.Size = New System.Drawing.Size(184, 20)
Me.TextBox4.TabIndex = 9
Me.TextBox4.Text = "TextBox4"
'
'TextBox5
'
Me.TextBox5.Location = New System.Drawing.Point(96, 128)
Me.TextBox5.Name = "TextBox5"
Me.TextBox5.Size = New System.Drawing.Size(184, 20)
Me.TextBox5.TabIndex = 10
Me.TextBox5.Text = "TextBox5"
'
'TextBox6
'
Me.TextBox6.Location = New System.Drawing.Point(96, 152)
Me.TextBox6.Name = "TextBox6"
Me.TextBox6.Size = New System.Drawing.Size(184, 20)
Me.TextBox6.TabIndex = 11
Me.TextBox6.Text = "TextBox6"
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(296, 32)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(88, 24)
Me.Button1.TabIndex = 12
Me.Button1.Text = "Annuler"
'
'Button2
'
Me.Button2.Location = New System.Drawing.Point(296, 64)
Me.Button2.Name = "Button2"
Me.Button2.Size = New System.Drawing.Size(88, 24)
Me.Button2.TabIndex = 13
Me.Button2.Text = "Valider"
'
'Button3
'
Me.Button3.Location = New System.Drawing.Point(296, 160)
Me.Button3.Name = "Button3"
Me.Button3.Size = New System.Drawing.Size(88, 24)
Me.Button3.TabIndex = 14
Me.Button3.Text = "Quitter"
'
'Button4
'
Me.Button4.Location = New System.Drawing.Point(296, 192)
Me.Button4.Name = "Button4"
Me.Button4.Size = New System.Drawing.Size(88, 23)
Me.Button4.TabIndex = 18
Me.Button4.Text = "Dernier"
'
'Button5
'
Me.Button5.Location = New System.Drawing.Point(8, 192)
Me.Button5.Name = "Button5"
Me.Button5.Size = New System.Drawing.Size(88, 23)
Me.Button5.TabIndex = 17
Me.Button5.Text = "Premier"
'
'Button6
'
Me.Button6.Location = New System.Drawing.Point(200, 192)
Me.Button6.Name = "Button6"
Me.Button6.Size = New System.Drawing.Size(88, 23)
Me.Button6.TabIndex = 16
Me.Button6.Text = "Suivant"
'
'Button7
'
Me.Button7.Location = New System.Drawing.Point(104, 192)
Me.Button7.Name = "Button7"
Me.Button7.Size = New System.Drawing.Size(88, 23)
Me.Button7.TabIndex = 15
Me.Button7.Text = "Précédent"
'
'Button8
'
Me.Button8.Location = New System.Drawing.Point(296, 128)
Me.Button8.Name = "Button8"
Me.Button8.Size = New System.Drawing.Size(88, 24)
Me.Button8.TabIndex = 20
Me.Button8.Text = "Suprimer"
'
'Button9
'
Me.Button9.Location = New System.Drawing.Point(296, 96)
Me.Button9.Name = "Button9"
Me.Button9.Size = New System.Drawing.Size(88, 24)
Me.Button9.TabIndex = 19
Me.Button9.Text = "Ajouter"
'
'Form3
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(392, 222)
Me.Controls.Add(Me.Button8)
Me.Controls.Add(Me.Button9)
Me.Controls.Add(Me.Button4)
Me.Controls.Add(Me.Button5)
Me.Controls.Add(Me.Button6)
Me.Controls.Add(Me.Button7)
Me.Controls.Add(Me.Button3)
Me.Controls.Add(Me.Button2)
Me.Controls.Add(Me.Button1)
Me.Controls.Add(Me.TextBox6)
Me.Controls.Add(Me.TextBox5)
Me.Controls.Add(Me.TextBox4)
Me.Controls.Add(Me.TextBox3)
Me.Controls.Add(Me.TextBox2)
Me.Controls.Add(Me.TextBox1)
Me.Controls.Add(Me.Label6)
Me.Controls.Add(Me.Label5)
Me.Controls.Add(Me.Label4)
Me.Controls.Add(Me.Label3)
Me.Controls.Add(Me.Label2)
Me.Controls.Add(Me.Label1)
Me.Name = "Form3"
Me.Text = "Form3"
Me.ResumeLayout(False)

End Sub

#End Region

Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
sql = "select * from Client"
macommande = New OleDbCommand(sql, connec)
adapt.SelectCommand = macommande
adapt.Fill(dset, "client")
bmb = BindingContext(dset, "Client")
affiche()
End Sub


voila la solution
merci tout le monde
ps : drahcir tu y étais presque
3
cs_drahcir Messages postés 745 Date d'inscription mardi 30 novembre 2004 Statut Membre Dernière intervention 15 septembre 2009 4
29 mars 2006 à 10:17
Salut,

c'est vrai que ça serait bien de savoir de quelle erreur il s'agit...

Mais ne devrais-tu pas définir ta requête sql avant d'instancier ton objet ODBCCommand? Je pencherais donc pour la solution de willi!

@+
0
Rejoignez-nous