Dim dt As DataTable = Nothing
Dim dt As New DataTable
If Index <> -1 And Index < (dt.Rows.Count - 1) Then
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question'Les Imports Imports MySql.Data.MySqlClient ' Require MySQL Connector .Net this is to import MySQL.NET (%windir%\assembly\GAC\MySql.Data\1.0.7.30072__c5687fc88969c44d\MySql.Data.dll) Imports System.Data.SqlClient 'dans ma form 'les declaration Dim HostConn As New MySqlConnection Dim da As MySqlDataAdapter Dim dt As DataTable Dim ds As New DataSet Dim i As Integer 'puis dans mon form_load HostConn.ConnectionString = "server=myserver;" _ & "user id=myuser;" _ & "password=mypass;" _ & "database=mydatabase" Try HostConn.Open() da = New MySqlDataAdapter("SELECT * FROM MySqlTest", HostConn) da.Fill(ds, "MySqlTest") For Me.i = 0 To ds.Tables(0).Rows.Count - 1 CheckedListBox1.Items.Add(ds.Tables(0).Rows(i)(1)) Next i Catch myerror As MySqlException MsgBox("" & myerror.Message, MsgBoxStyle.Critical) End Try
CREATE TABLE IF NOT EXISTS `MySqlTest` ( `SQLID` smallint(6) unsigned NOT NULL, `SQLName` tinytext COLLATE latin1_general_ci NOT NULL, `SQLMetier` text COLLATE latin1_general_ci NOT NULL, `SQLPays` text COLLATE latin1_general_ci NOT NULL, `SQLSiteWeb` text COLLATE latin1_general_ci NOT NULL, PRIMARY KEY (`SQLID`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci; INSERT INTO `MySqlTest` (`SQLID`, `SQLName`, `SQLMetier`, `SQLPays`, `SQLSiteWeb`) VALUES (1, 'Eric', 'Cuisto', 'France', 'http://..'), (2, 'Jean', 'Militaire', 'Espagne', 'http://..'), (3, 'Paul', 'Vendeur', 'Etats Unis', 'http://..');
Using conn As MySqlConnection = New MySqlConnection("server=myserver; uid=myuser;pwd=mypass;database=mydatabase;") Using cmd As MySqlCommand = New MySqlCommand("SELECT SQLMetier FROM MySqlTest where SQLName='" & CheckedListBox1.Text & "'", conn) conn.Open() Using reader As MySqlDataReader = cmd.ExecuteReader() While reader.Read() Label1.Text = reader("id") End While End Using End Using End Using
Imports MySql.Data.MySqlClient Imports System.Data.SqlClient ' Public Class Form1 ' Dim dt As DataTable = Nothing ' Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load ' Dim HostConn As New MySqlConnection("ta chaine de connexion") Try Dim da As New MySqlDataAdapter("SELECT * FROM MySqlTest", HostConn) HostConn.Open() da.Fill(dt) For Each Row As DataRow In dt.Rows CheckedListBox1.Items.Add(Row.Item("SQLName")) Next Catch myerror As MySqlException MsgBox(myerror.Message, MsgBoxStyle.Critical) Finally If HostConn.State <> ConnectionState.Closed Then HostConn.Close() End If End Try ' End Sub Private Sub CheckedListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckedListBox1.SelectedIndexChanged ' Dim Index As Integer = CheckedListBox1.SelectedIndex If Index <> -1 And Index < (dt.Rows.Count - 1) Then Label1.Text = dt.Rows(Index).Item("SQLMetier") Label2.Text = dt.Rows(Index).Item("SQLPays") Label3.Text = dt.Rows(Index).Item("SQLSiteWeb") End If ' End Sub ' End Class
Dim HostConn As New MySqlConnection("ta chaine de connexion")
If Index <> -1 And Index < (dt.Rows.Count - 1) Then
If Index <> -0 And Index < (dt.Rows.Count - 0) Then
If Index <> -1 And Index < (dt.Rows.Count - 1) Then
If Index <> -1 And Index < (dt.Rows.Count - 0) Then