我试图加载一个下拉列表链接到一个表在mysql中的网页形式asp.net在vb中。我使用的类具有以下代码:
Public Class ClCountries
Public Function Read(ByVal Opcion As Integer) As DataTable
Dim cnn As New MySqlConnection(ConfigurationManager.ConnectionStrings("cnnPortalSmart").ConnectionString)
Dim dt As New DataTable
Try
Dim cmd As New MySqlCommand("PA_COUNTRIES_SELECT", cnn)
cmd.CommandType = CommandType.StoredProcedure
cmd.Parameters.AddWithValue("@Opcion", Opcion)
cnn.Open()
dt.Load(cmd.ExecuteReader(), LoadOption.OverwriteChanges)
cnn.Close()
Catch ex As Exception
Dim msgError As String
msgError = ex.Message.ToString()
cnn.Close()
End Try
Return dt
End Function
End Class
它是通过以下方法从page\u load()调用的:
Sub LoadCountries()
Try
Dim dv As New DataView(New ClCountries().Read(1))
ddlCountry.DataSource = dv
ddlCountry.DataTextField = "Name"
ddlCountry.DataValueField = "ID"
ddlCountry.DataBind()
Dim li As New ListItem("Select Country", "0")
ddlCountry.Items.Insert(0, li)
Catch ex As Exception
End Try
End Sub
aspx中的连接字符串:
<connectionStrings>
<add name="cnnPortalSmart" connectionString="Data Source=IP_NUMBER;Initial Catalog=SCHEMA_NAME; User ID=root;Password=XXXX;" providerName="MySql.Data.MySqlClient" />
</connectionStrings>
谢谢您。
2条答案
按热度按时间waxmsbnn1#
我通过将连接字符串修改为:
1qczuiv02#
希望这对你有帮助