我目前正在vb.net上建立一个多学校测验计划,用于学校的分配。问题,选项和答案都存储在微软访问文件(.mdb)的表中。我已将其作为数据连接导入并创建了包含该表的数据链接。我当前的问题是将表中的字符串移动到一个数组,以便可以显示和比较它们(用于自动标记)。通过这个障碍将是一个很大的帮助。
谢谢,
答案 0 :(得分:0)
有人可能会提供更有效的答案,但我这样做的方式如下:
'create the connection, replace with the relevant connection string and database file
Dim con As New OleDbConnection
con.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source = db.mdb"
con.Open()
'ready for loading, creating new datatables and sets to load the data from the database into.
Dim dt As New DataTable
Dim ds As New DataSet
ds.Tables.Add(dt)
Dim da As New OleDbDataAdapter
' your query - change to what is needed.
da = New OleDbDataAdapter("Select * from TABLE", con)
da.Fill(dt)
'fill into a datagridview, which you need to add to the form
DataGridView1.DataSource = dt.DefaultView
con.Close()
'create the array, change x to how many entries
Dim arr(0 To x) As String
'check the datagridview for where the data is being filled to. Adds the value of position 0,0 in the DGV to position arr(0), for example. first is row, second is column.
arr(0) = DataGridView1.Item(0, 0).Value
arr(1) = DataGridView1.Item(1, 0).Value
arr(2) = DataGridView1.Item(2, 0).Value
arr(3) = DataGridView1.Item(3, 0).Value
arr(4) = DataGridView1.Item(4, 0).Value
arr(5) = DataGridView1.Item(5, 0).Value
arr(6) = DataGridView1.Item(6, 0).Value
arr(7) = DataGridView1.Item(7, 0).Value
arr(8) = DataGridView1.Item(8, 0).Value