Dataadapter.update抛出错误;数据表localdb中的datacollumn rwuser for sourcecollumn rwuser不会被激活 [英] Dataadapter.update throws error; datacollumn rwuser in datatable localdb for sourcecollumn rwuser doesn't excist
问题描述
亲爱的,
我正在尝试用多个表更新数据集。但是,我想要更新时间,我要更新的第一个表会抛出一个错误,该列不会在该表中出现错误。这确实是通过,但是在我想要更新的最后一个表中只有列表。我确实尝试交换(放在最后一个和所有)但仍然是继续给我相同的错误与相同的collumn名称。
总是缺少collumn rwUser ..除了里面有rwUser的表格,这将正确完成。
我的代码下面有我以及我所有的表格和行。
我使用Access 2016创建的数据库,是一个aacdb。我正在使用Visual Basic 2017
数据库;
以tb开头的单词是Tables。
Dear all,
I am trying to update a dataset with multiple tables. However evertime I want to update, the first table that I want to update throws an error, that collumn doesn't excist in that table. This is indeed thru, but the collumn only excist in the last table I want to update. I did try to swap (put last first and all) but still it is keep giving me the same error with the same collumn name.
Always it is missing collumn rwUser..except in the table with the rwUser inside this will be done correctly.
Below my code I have and also all the tables and rows I have.
The Database I created with Access 2016 and is an aacdb. And I am using Visual Basic 2017
The Database;
Words starting with tb are the Tables.
The Tables / rows I have;
• tbAuthorizations
o AuthorizationID
o rwAuthorization (this to be used as sourch for table tbUsersAuthorizations / rwSetUser, rwSetData, rwSetSettings, rwSetReports
• tbLocalDataFolder
o LocalDataBaseID
o rwDatabase
o rwLocation
• tbServerDataFolder
o ServerDatabaseID
o rwDatabase
o rwLocation
• tbUserAuthorizations
o UserAuthorizationID
o rwAuthUser = Lookup / relation of tbUsers – rwUserID
o rwSetUser = Lookup / relation of tbAuthorizations - AuthorizationID
o rwSetData = Lookup / relation of tbAuthorizations - AuthorizationID
o rwIncludeFixData
o rwSetSettings = Lookup / relation of tbAuthorizations - AuthorizationID
o rwSetReports = Lookup / relation of tbAuthorizations – AuthorizationID
• tbUsers
o UserID
o rwUser (this to be used as sourch for table tbUsersAuthorizations – rwUser)
o rwInlogName
o rwPassword
o rwSercretQuestion
o rwSecretAnswer
o rwEmail
o rwComputerName
o rwWindowsUser
o rwPasswordLogin
o rwHoldOnStart
o rwRememberName
o rwRememberPassword
我的尝试:
What I have tried:
Public Class Form1
Dim con As New OleDb.OleDbConnection
Dim dbProvider As String
Dim dbSource As String
Dim dbFolder As String
Dim dbName As String
Dim ds As New DataSet
Dim da As OleDb.OleDbDataAdapter
Dim sql As String
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
dbProvider = "PROVIDER=MICROSOFT.ACE.OLEDB.12.0;"
dbName = "D:\SystemSettings.accdb"
dbSource = "DATA SOURCE = " & dbName
con.ConnectionString = dbProvider & dbSource
con.Open()
da = New OleDb.OleDbDataAdapter("SELECT * FROM tbAuthorizations", con)
da.Fill(ds, "AuthDB")
da.SelectCommand.CommandText = "SELECT * FROM tbLocalDataFolder"
da.Fill(ds, "LocalDB")
da.SelectCommand.CommandText = "SELECT * FROM tbServerDataFolder"
da.Fill(ds, "ServerDB")
da.SelectCommand.CommandText = "SELECT * FROM tbUserAuthorizations"
da.Fill(ds, "UserAuthDB")
da.SelectCommand.CommandText = "SELECT * FROM tbUsers"
da.Fill(ds, "UsersDB")
con.Close()
End Sub
Private Sub BtnUpdate_Click(sender As Object, e As EventArgs) Handles btnUpdate.Click
Dim cb As New OleDb.OleDbCommandBuilder(da)
Dim dsNewRow As DataRow
Try
dsNewRow = ds.Tables("UsersDB").NewRow()
dsNewRow.Item("rwUser") = txtNaam.Text
dsNewRow.Item("rwInlogName") = TxtGeboorteplaats.Text
ds.Tables("UsersDB").Rows.Add(dsNewRow)
da.Update(ds, "UsersDB")
dsNewRow = ds.Tables("LocalDB").NewRow()
dsNewRow.Item("rwDatabase") = txtNaam.Text
dsNewRow.Item("rwLocation") = TxtGeboorteplaats.Text
ds.Tables("LocalDB").Rows.Add(dsNewRow)
da.Update(ds, "LocalDB") ''exception error; DataCollumn rwUser in DataTable LocalDB for SourceCollumn rwUser doesn't excist
dsNewRow = ds.Tables("ServerDB").NewRow()
dsNewRow.Item("rwDatabase") = txtNaam.Text
dsNewRow.Item("rwLocation") = TxtGeboorteplaats.Text
ds.Tables("ServerDB").Rows.Add(dsNewRow)
da.Update(ds, "ServerDB") ''exception error; DataCollumn rwUser in DataTable ServerDB for SourceCollumn rwUser doesn't excist
dsNewRow = ds.Tables("UserAuthDB").NewRow()
dsNewRow.Item("rwAuthUser") = txtNaam.Text
dsNewRow.Item("rwSetUser") = TxtGeboorteplaats.Text
ds.Tables("UserAuthDB").Rows.Add(dsNewRow)
da.Update(ds, "UserAuthDB") ''exception error; DataCollumn rwUser in DataTable UserAuthDB for SourceCollumn rwUser doesn't excist
Catch ex As Exception
Dim s As String
s = ex.StackTrace
End Try
End Sub
End Class
推荐答案
Hello Richard
这就是问题所在。为什么VB调用这一行?我知道它是在异常中说列,但我认为它正在解决行。但是在代码中我没有解决这一行,只是在tbUser的更新中有这样的行。
我没有使用这个专栏,从来没有。唯一一个有一行名为rwUser的表就是表tbUsers。如果我只使用tbUsers进行更新,则没有问题。那么为什么确实是VB给了我其他表中的错误,其中确实没有rwUser。
如果代码中有错误,那么请让我知道,我试图在除了tbUsers之外的所有表格中使用该列。
但是VB说这不是表格中的问题LocalDB,tbServerDB和tbUserAuthorizations。
问候,
Hans
Hello Richard
That is the problem. Why is VB calling this row? I know it is saying column in the exception, but I assume it is addressing the row.But inside the code I am not addressing this row, only in the update for tbUser where there is such row.
I am not using this column, never had. The only table that has a row called rwUser is the table tbUsers. And if I only use tbUsers to update, there is no problem. So why indeed, is VB give me the error in the other tables, which indeed don't have rwUser inside.
And if there is something wrong in the code, then please let me know, where I am trying to use that column in all the tables except the tbUsers.
But VB is saying that this doesn't excist in table LocalDB, tbServerDB and tbUserAuthorizations.
Regards,
Hans
Hello Richard,>
我正在使用debuger,每次遇到da.update时都会出现错误。
如果我删除tbUsers int da / ds那么错误将是rwAuthUser不在表中。但是当我只更新tbUserAuthorizations时,它就没事了。
以上代码就是我所拥有的。所以似乎da.update命令对于多个表数据库是不正确的,或者我需要在里面有额外的东西。
但是我会试着看。无论如何,谢谢你的回复
Hello Richard,
I am using the debuger and everytime when it hits the da.update it is going in that error.
If I remove the tbUsers int he da/ds then the error will be that rwAuthUser is not in the table. But then when I only update tbUserAuthorizations, it is going okay.
And the above code is all I have. So it seems that the da.update comand is not correct for multiple table database or I need to have something extra inside.
But I will try to see. Thanks anyway for your replies
亲爱的,
我找到了一种方法让它工作,但不确定是否在结束它不会产生问题,例如DS和数据库之间的列/行的差异。如果那时数据集,Dataadapter和数据库是同步的。
我现在将ds.tables与insert的查询结合起来。 ds.tables已经/已经在上面的代码中更新。但是我遇到da.update的问题而且这个da.update我想使用查询,所以我有;
Dear all,
I found a way to make it work, but not sure if in the end it will not creating problems, like difference of collumn / row between DS and the Database. If then the Dataset, Dataadapter and Database are in sync.
I now have combined ds.tables with a query for insert. ds.tables is/was already updated in the above code. But I run in problem with da.update and for this da.update I want to use a query, so I have then;
Private Sub BtnUpdate_Click(sender As Object, e As EventArgs) Handles btnUpdate.Click
Dim cb As New OleDb.OleDbCommandBuilder(da)
Dim dsNewRow As DataRow
Dim query As String
Dim i As Integer
Try
dsNewRow = ds.Tables("UsersDB").NewRow()
dsNewRow.Item("rwUser") = txtNaam.Text
dsNewRow.Item("rwInlogName") = TxtGeboorteplaats.Text
ds.Tables("UsersDB").Rows.Add(dsNewRow)
query = "INSERT INTO tbLocalDataFolder (rwDatabase,rwLocation) VALUES ('" & txtNaam.Text & "','" & TxtGeboorteplaats.Text & "')"
executquery(query, con)
dsNewRow.Item("rwDatabase") = txtNaam.Text
dsNewRow.Item("rwLocation") = TxtGeboorteplaats.Text
ds.Tables("LocalDB").Rows.Add(dsNewRow)
query = "INSERT INTO tbLocalDataFolder (rwDatabase,rwLocation) VALUES ('" & txtNaam.Text & "','" & TxtGeboorteplaats.Text & "')"
executquery(query, con)
Catch ex As Exception
Dim s As String
s = ex.StackTrace
End Try
End Sub
Public Sub executquery(query As String, connec As OleDb.OleDbConnection)
Dim commandOleDb As New OleDb.OleDbCommand(query, connec)
con.Open()
commandOleDb.ExecuteNonQuery()
con.Close()
End Sub
这篇关于Dataadapter.update抛出错误;数据表localdb中的datacollumn rwuser for sourcecollumn rwuser不会被激活的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!