我目前正在完成一个项目,其中一系列组合框有望链接回单个数据库记录,我将获取5个值,我有以下代码如何输出它已返回的记录,以便我可以使用用户尚未在代码的后半部分输入表中的值?
myConnection.ConnectionString = My.Forms.Main.connString
myConnection.Open()
Dim match As String = "SELECT CBrand, CModel, CSpec,BodyStyle,CNoOfDoors, CEngineSize, COTR, TransmissionCost
FROM CarFigures WHERE CBrand = cbBrand.text
CModel = cbModel.text
CSpec = cbSpec.text
CNoOfDoors = cbNoOfDoors.text
EngineSize = cbEngineSize.text"
答案 0 :(得分:0)
打开连接并进行查询后,您需要执行此操作:
myConnection.ConnectionString = My.Forms.Main.connString
myConnection.Open()
Dim match As String = "SELECT CBrand, CModel, ..."
' define data adapter, data set, fill data set then loop'
Dim da As New OleDb.OleDbDataAdapter
Dim ds As New Dataset
Dim row As System.Data.DataRow
Dim count As Integer
da.SelectCommand = New OleDb.OleDbCommand(match, myConnection)
da.Fill(ds, "myTable")
count = ds.Tables("myTable").Rows.Count
While count > -1
row = ds.Tables("myTable").Rows.Item(count)
' this is where you take row.Item(0) and do something with it... '
count = count - 1
End While
myConnection.Close()