VB.net中的OleDb只返回第一列
我不知道自己哪里出错了,连续2个小时盯着它看了150种不同的变化。不知道错误在哪里使得它不会返回除第一个之外的任何其他字段。
是的,我知道它看起来真的很混乱,我打算将5个读数作为一个功能,但我被问题所困扰
Traceback (most recent call last):
File "<ipython-input-7-e80e82960eb9>", line 1, in <module>
cross = cross_val_score(estimator=classfier, X=Xtrain, y=Ytrain, cv=10 , n_jobs=-1)
File "C:\Users\Joish\Anaconda3\envs\project\lib\site-packages\sklearn\model_selection\_validation.py", line 342, in cross_val_score
pre_dispatch=pre_dispatch)
File "C:\Users\Joish\Anaconda3\envs\project\lib\site-packages\sklearn\model_selection\_validation.py", line 206, in cross_validate
for train, test in cv.split(X, y, groups))
File "C:\Users\Joish\Anaconda3\envs\project\lib\site-packages\sklearn\externals\joblib\parallel.py", line 779, in __call__
while self.dispatch_one_batch(iterator):
File "C:\Users\Joish\Anaconda3\envs\project\lib\site-packages\sklearn\externals\joblib\parallel.py", line 620, in dispatch_one_batch
tasks = BatchedCalls(itertools.islice(iterator, batch_size))
File "C:\Users\Joish\Anaconda3\envs\project\lib\site-packages\sklearn\externals\joblib\parallel.py", line 127, in __init__
self.items = list(iterator_slice)
File "C:\Users\Joish\Anaconda3\envs\project\lib\site-packages\sklearn\model_selection\_validation.py", line 206, in <genexpr>
for train, test in cv.split(X, y, groups))
File "C:\Users\Joish\Anaconda3\envs\project\lib\site-packages\sklearn\base.py", line 62, in clone
new_object_params[name] = clone(param, safe=False)
File "C:\Users\Joish\Anaconda3\envs\project\lib\site-packages\sklearn\base.py", line 53, in clone
return copy.deepcopy(estimator)
File "C:\Users\Joish\Anaconda3\envs\project\lib\copy.py", line 180, in deepcopy
y = _reconstruct(x, memo, *rv)
File "C:\Users\Joish\Anaconda3\envs\project\lib\copy.py", line 280, in _reconstruct
state = deepcopy(state, memo)
File "C:\Users\Joish\Anaconda3\envs\project\lib\copy.py", line 150, in deepcopy
y = copier(x, memo)
File "C:\Users\Joish\Anaconda3\envs\project\lib\copy.py", line 240, in _deepcopy_dict
y[deepcopy(key, memo)] = deepcopy(value, memo)
File "C:\Users\Joish\Anaconda3\envs\project\lib\copy.py", line 150, in deepcopy
y = copier(x, memo)
File "C:\Users\Joish\Anaconda3\envs\project\lib\copy.py", line 215, in _deepcopy_list
append(deepcopy(a, memo))
File "C:\Users\Joish\Anaconda3\envs\project\lib\copy.py", line 180, in deepcopy
y = _reconstruct(x, memo, *rv)
File "C:\Users\Joish\Anaconda3\envs\project\lib\copy.py", line 280, in _reconstruct
state = deepcopy(state, memo)
File "C:\Users\Joish\Anaconda3\envs\project\lib\copy.py", line 150, in deepcopy
y = copier(x, memo)
File "C:\Users\Joish\Anaconda3\envs\project\lib\copy.py", line 240, in _deepcopy_dict
y[deepcopy(key, memo)] = deepcopy(value, memo)
File "C:\Users\Joish\Anaconda3\envs\project\lib\copy.py", line 150, in deepcopy
y = copier(x, memo)
File "C:\Users\Joish\Anaconda3\envs\project\lib\copy.py", line 215, in _deepcopy_list
append(deepcopy(a, memo))
File "C:\Users\Joish\Anaconda3\envs\project\lib\copy.py", line 180, in deepcopy
y = _reconstruct(x, memo, *rv)
File "C:\Users\Joish\Anaconda3\envs\project\lib\copy.py", line 280, in _reconstruct
state = deepcopy(state, memo)
File "C:\Users\Joish\Anaconda3\envs\project\lib\copy.py", line 150, in deepcopy
y = copier(x, memo)
File "C:\Users\Joish\Anaconda3\envs\project\lib\copy.py", line 240, in _deepcopy_dict
y[deepcopy(key, memo)] = deepcopy(value, memo)
File "C:\Users\Joish\Anaconda3\envs\project\lib\copy.py", line 180, in deepcopy
y = _reconstruct(x, memo, *rv)
File "C:\Users\Joish\Anaconda3\envs\project\lib\copy.py", line 280, in _reconstruct
state = deepcopy(state, memo)
File "C:\Users\Joish\Anaconda3\envs\project\lib\copy.py", line 150, in deepcopy
y = copier(x, memo)
File "C:\Users\Joish\Anaconda3\envs\project\lib\copy.py", line 240, in _deepcopy_dict
y[deepcopy(key, memo)] = deepcopy(value, memo)
File "C:\Users\Joish\Anaconda3\envs\project\lib\copy.py", line 180, in deepcopy
y = _reconstruct(x, memo, *rv)
File "C:\Users\Joish\Anaconda3\envs\project\lib\copy.py", line 280, in _reconstruct
state = deepcopy(state, memo)
File "C:\Users\Joish\Anaconda3\envs\project\lib\copy.py", line 150, in deepcopy
y = copier(x, memo)
File "C:\Users\Joish\Anaconda3\envs\project\lib\copy.py", line 240, in _deepcopy_dict
y[deepcopy(key, memo)] = deepcopy(value, memo)
File "C:\Users\Joish\Anaconda3\envs\project\lib\copy.py", line 180, in deepcopy
y = _reconstruct(x, memo, *rv)
File "C:\Users\Joish\Anaconda3\envs\project\lib\copy.py", line 280, in _reconstruct
state = deepcopy(state, memo)
File "C:\Users\Joish\Anaconda3\envs\project\lib\copy.py", line 150, in deepcopy
y = copier(x, memo)
File "C:\Users\Joish\Anaconda3\envs\project\lib\copy.py", line 240, in _deepcopy_dict
y[deepcopy(key, memo)] = deepcopy(value, memo)
File "C:\Users\Joish\Anaconda3\envs\project\lib\copy.py", line 169, in deepcopy
rv = reductor(4)
TypeError: can't pickle _thread.lock objects
答案 0 :(得分:0)
循环外部有一个连接,循环内有几个命令。虽然这是朝着正确的方向倾斜,但每个命令都包含在以连接对象为目标的Using
块内。这意味着在第一次通过循环的第一个命令结束时,你的连接处理,使连接无法使用。
虽然我在这里,但您还应该查看参数化查询。
将所有这些以及其他一些更改放在一起,您最终会得到:
Dim temp_QuestionSet As New List(Of Question)
Private Sub StartBtn_Click(sender As Object, e As EventArgs) Handles StartBtn.Click
temp_QuestionSet.Clear()
Dim QuestionSql As String = "SELECT Question, Answer1, Answer2, Answer3, Answer4, CorrectAnswer FROM final WHERE QuestionID = ?"
provider = "Provider=Microsoft.ACE.OLEDB.12.0;"
dataFile = "Data Source=C:\course work\dttmq.accdb"
connString = provider & dataFile
Using Connection As New OleDbConnection(connString), _
command As New OleDbCommand(QuestionSql, Connection)
command.Parameters.Add("ID", OleDbType.Integer)
Connection.Open()
For Each Number In Enumerable.Range(0,15).Select(Function(i) RandomNum())
command.Parameters("ID").Value = Number
Try
Dim reader As OleDbDataReader = command.ExecuteReader()
While reader.Read()
temp_QuestionSet.Add(New Question With {
.ID = Number,
.Q = reader("Question").ToString(),
.A = reader("Answer1").ToString(),
.B = reader("Answer2").ToString(),
.C = reader("Answer3").ToString(),
.D = reader("Answer4").ToString(),
.Z = reader("CorrectAnswer").ToString())
End While
reader.Close()
Catch ex As Exception
MsgBox("Error: " & ex.Message)
Console.Beep()
End Try
Next
End Using
End Sub
我还要考虑将这个问题归结为您的数据库的一次访问,一次性加载所有问题,然后将结果洗牌。我提供的代码应该可以很容易地朝着这个方向前进,只需更改SQL命令即可完成此任务。