gpt4 book ai didi

mysql - 将 mysql 数据库绑定(bind)到下拉列表 vb.net

转载 作者:行者123 更新时间:2023-11-30 22:33:45 24 4
gpt4 key购买 nike

我需要帮助将 MySQL 数据库绑定(bind)到下拉列表。

这是我通常连接到数据库的方式

Dim connectionstring As String = ConfigurationManager.ConnectionStrings("DBstring").ConnectionString
Dim connectme As OdbcConnection = New OdbcConnection(connectionstring)
Dim ODBCdataset As DataSet = New DataSet()
Dim sqlquery As String = "SELECT * FROM treconcalculation WHERE fid = " & Request.QueryString("id")
connectme.Open()
Dim ODBCdataadapter As OdbcDataAdapter = New OdbcDataAdapter(sqlquery, connectme)
ODBCdataadapter.Fill(ODBCdataset, "treconcalculation")
connectme.Close()

make1 = ODBCdataset.Tables("treconcalculation").Rows(0).Item(1)
model1 = ODBCdataset.Tables("treconcalculation").Rows(0).Item(2)
cc1 = ODBCdataset.Tables("treconcalculation").Rows(0).Item(3)
below2 = ODBCdataset.Tables("treconcalculation").Rows(0).Item(4)
below3 = ODBCdataset.Tables("treconcalculation").Rows(0).Item(5)
below4 = ODBCdataset.Tables("treconcalculation").Rows(0).Item(6)
below5 = ODBCdataset.Tables("treconcalculation").Rows(0).Item(7)
above5 = ODBCdataset.Tables("treconcalculation").Rows(0).Item(8)

我该如何将其应用到下拉列表中?我试过了

Dim constr As String = ConfigurationManager.ConnectionStrings("DBstring").ConnectionString
Using con As New SqlConnection(constr)
Using cmd As New SqlCommand("SELECT fid, fmake, fmodel FROM treconcalculation")
cmd.CommandType = CommandType.Text
cmd.Connection = con
Using sda As New SqlDataAdapter(cmd)
Dim ds As New DataSet()
sda.Fill(ds)
vehicle1.DataSource = ds.Tables(0)
vehicle1.DataTextField = "fmodel"
vehicle1.DataValueField = "fid"
vehicle1.DataBind()
End Using
End Using
End Using
vehicle1.Items.Insert(0, New ListItem("--Select Customer--", "0"))

然后出现错误,提示不支持关键字:“驱动程序”。

谢谢

最佳答案

所以问题不在于 DropDown 绑定(bind):它在于连接字符串,您用来连接到数据库:我请求您检查您的机器上是否安装了 ODBC Driver 3.51 并检查具有所有有效参数的连接字符串。如果您在代码中构建连接字符串,我建议您像下面这样使用:

Dim _DbHost = "localhost";
Dim _DbName = "yourDBName";
Dim _DbPassWord = "DbUser";
Dim _DbUser = "*****";
Dim ConString = "Driver={MySQL ODBC 3.51 Driver};" +
"Server=" + DbHost + ";" +
"Database=" + DbName + ";" +
"User=" + DbUser + ";" +
"Password=" + DbPassWord + ";" +
"option=3;"

关于mysql - 将 mysql 数据库绑定(bind)到下拉列表 vb.net,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33139801/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com