SELECT plusieurs enregistrement
bonjour, j'ai 2 questions ? donc voici mon code:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| Private Sub test1()
Dim MyConnexion As OleDbConnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data source=C:\develop\Test oracle\bd_test.mdb")
Dim Mycommand As OleDbCommand = MyConnexion.CreateCommand()
Mycommand.CommandText = "SELECT CTYGA FROM ARTCOM"
MyConnexion.Open()
Dim myREADER As OleDbDataReader = Mycommand.ExecuteReader()
Do While myREADER.Read()
TextBox2.Text = TextBox2.Text & vbCrLf & myREADER.GetString(0)
Loop
myREADER.Close()
MyConnexion.Close()
End Sub |
et voici la structure de ma table:
http://nsa25.casimages.com/img/2011/...4845853353.png
1) le problème c'est que dans le champ : 'CTYGA' je suis en format numérique... et j'ai une erreur de CAST...
j'ai essayer ça:
Code:
TextBox2.Text = TextBox2.Text & vbCrLf & CStr(myREADER.GetString(0))
mais toujours pareil... si quelqu'un peux m'aider ?
2) sinon est ce que je peux récuperer l'integraliter des enregistrements plus simplement que ça:
Code:
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 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
| Private Sub test()
Dim MyConnexion As OleDbConnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data source=C:\develop\Test oracle\bd_test.mdb")
Dim MycommandNGAMM As OleDbCommand = MyConnexion.CreateCommand()
Dim MycommandCSITG As OleDbCommand = MyConnexion.CreateCommand()
Dim MycommandCDATL As OleDbCommand = MyConnexion.CreateCommand()
Dim MycommandCTYGA As OleDbCommand = MyConnexion.CreateCommand()
Dim MycommandNENCH As OleDbCommand = MyConnexion.CreateCommand()
Dim MycommandNPHSE As OleDbCommand = MyConnexion.CreateCommand()
Dim MycommandCTYPH As OleDbCommand = MyConnexion.CreateCommand()
Dim MycommandNSECG As OleDbCommand = MyConnexion.CreateCommand()
Dim MycommandNOUDC As OleDbCommand = MyConnexion.CreateCommand()
Dim MycommandLOBSG As OleDbCommand = MyConnexion.CreateCommand()
MycommandNGAMM.CommandText = "SELECT NGAMM FROM ARTCOM"
MycommandCSITG.CommandText = "SELECT CSITG FROM ARTCOM"
MycommandCDATL.CommandText = "SELECT CDATL FROM ARTCOM"
MycommandCTYGA.CommandText = "SELECT CTYGA FROM ARTCOM"
MycommandNENCH.CommandText = "SELECT NENCH FROM ARTCOM"
MycommandNPHSE.CommandText = "SELECT NPHSE FROM ARTCOM"
MycommandCTYPH.CommandText = "SELECT CTYPH FROM ARTCOM"
MycommandNSECG.CommandText = "SELECT NSECG FROM ARTCOM"
MycommandNOUDC.CommandText = "SELECT NOUDC FROM ARTCOM"
MycommandLOBSG.CommandText = "SELECT LOBSG FROM ARTCOM"
MyConnexion.Open()
Dim myNGAMM As OleDbDataReader = MycommandNGAMM.ExecuteReader()
Dim myCSITG As OleDbDataReader = MycommandCSITG.ExecuteReader()
Dim myCDATL As OleDbDataReader = MycommandCDATL.ExecuteReader()
Dim myCTYGA As OleDbDataReader = MycommandCTYGA.ExecuteReader()
Dim myNENCH As OleDbDataReader = MycommandNENCH.ExecuteReader()
Dim myNPHSE As OleDbDataReader = MycommandNPHSE.ExecuteReader()
Dim myCTYPH As OleDbDataReader = MycommandCTYPH.ExecuteReader()
Dim myNSECG As OleDbDataReader = MycommandNSECG.ExecuteReader()
Dim myNOUDC As OleDbDataReader = MycommandNOUDC.ExecuteReader()
Dim myLOBSG As OleDbDataReader = MycommandLOBSG.ExecuteReader()
Do While myNGAMM.Read() And myCSITG.Read() And myCDATL.Read() And myCTYGA.Read() And myNENCH.Read() And myNPHSE.Read() And myCTYPH.Read() And myNSECG.Read() And
myNOUDC.Read() And myLOBSG.Read()
TextBox2.Text = TextBox2.Text & vbCrLf & myNGAMM.GetString(0) & "|" & myCSITG.GetString(0) & "|" & myCDATL.GetString(0) & "|" & myCTYGA.GetString(0) & "|" & myNENCH.GetString(0) & "|" & myNPHSE.GetString(0) & "|" & myCTYPH.GetString(0) & "|" & myNSECG.GetString(0) & "|" & myNOUDC.GetString(0) & "|" & myLOBSG.GetString(0)
Loop
Do While myCTYGA.Read()
'ListBox1.Items.Add(myCTYGA.GetString(0))
TextBox2.Text = TextBox2.Text & vbCrLf & CStr(myCTYGA.GetString(0))
Loop
myNGAMM.Close()
MyConnexion.Close()
End Sub |
??????
merci