INCLUDE_DATA

One of the things I often do with my website is populate a Dropdownlist1 with information from a MYSQL database. Here is an example code which I use to do that:
[code language=”vb”]Dim myConnectionString As String = System.Configuration.ConfigurationManager.ConnectionStrings("myConnectionString").ConnectionString
Dim conn As MySqlConnection = New MySqlConnection(myConnectionString)
Dim cmd As MySqlCommand = New MySqlCommand(myConnectionString)
Dim sqlString As String = Nothing
Dim myConnection As New MySqlConnection(myConnectionString)
Dim myAdapter As MySqlDataAdapter = New MySqlDataAdapter(sqlString, myConnection)
Dim DS As DataSet = New DataSet

myAdapter.SelectCommand.CommandText = "select ID,MyDescription from Mydropdowntable"
myAdapter.Fill(DS)
Dim RText As String = "[Please Select]"
Me.Dropdownlist1.Items.Clear()
If DS.Tables(0).Rows.Count > 0 Then
For i As Integer = 0 To DS.Tables(0).Rows.Count – 1
Me.Dropdownlist1.Items.Insert(0, New ListItem(DS.Tables(0).Rows(i).Item(0).ToString, DS.Tables(0).Rows(i).Item(0).ToString))
Next
Else
RText = "Nothing Available"
End If
Me.Dropdownlist1.Items.Insert(0, New ListItem(RText, "0"))

myAdapter.Dispose()
myConnection.Dispose()
DS.Dispose()[/code].
I am connecting to a MYSQL database and are using Devart .Net Database connection with VS2008

You have to import the following at the beginning:
[code language=”vb”]Imports System.Data
Imports CoreLab.MySql[/code].

SEO Powered by Platinum SEO from Techblissonline