1
我需要將MySQL數據庫綁定到下拉列表的幫助。將mysql數據庫綁定到下拉列表vb.net
這裏是如何我通常連接到數據庫
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"))
並且出現一個錯誤提示說不支持關鍵字:'driver'。
感謝
哪條線給你那個錯誤? –
我發現這條線出了問題。 connectionString =「DRIVER = {MySQL ODBC 3.51 Driver}是否可以將腳本更改爲ODBC驅動程序? – Jacklck