帮助 - 问题让DataAdapter更新 [英] Help - Problem Getting DataAdapter to update

查看:67
本文介绍了帮助 - 问题让DataAdapter更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我似乎遇到了针对Access数据库的DataAdapter问题。

我的应用删除3条记录运行da.update(dt) dt是一个data.Datatable。

然后我继续更新一个列表,以反映这3个项目已被删除,但只发现了3个项目,但是当我点击

他们显示他们在同一个

数据库上运行datareader的信息,看起来数据已经消失了。


我想知道这是否是一个计时问题,我试着插入一个计时器,这个计时器等待了半秒,然后更新了列表,但它仍然不是
工作。

如果我退出表格,所有这些都在运行(它是一个MDI应用程序,所以我不会b / b $ b b关闭应用程序)然后重新打开它(创建一个新的实例),列表是好的b
反映了这3个项目已被删除的事实??


任何人都知道我为什么要这样做ef?


基本上代码是:

删除部分:


Dim CB作为OleDb.OleDbCommandBuilder, DT As Data.DataTable,DA As

OleDb.OleDbDataAdapter

Dim StrSQL As String,Cn As OleDb.OleDbConnection

Dim NumRows As Integer, n作为整数


尝试

StrSQL ="从发票中选择*,其中[发票编号] =" &

InvNum& " AND DeletedYN = False ORDER BY PartPaymentNumber desc;"

Cn = New OleDb.OleDbConnection(DefCon& DBFilePath)

Cn.Open()

DA =新OleDb.OleDbDataAdapter(StrSQL,Cn)

DT =新Data.DataTable

CB =新OleDb.OleDbCommandBuilder(DA)

CB.QuotePrefix =" ["

CB.QuoteSuffix ="]"

DA.Fill(DT)


NumRows = DT.Rows.Count

如果NumRows> 0然后

''我们有一些记录

''记录将按部件号逆序排列,即,如果是3

parter,这将是b $ b''是3,2,1。我们可以从数据库中删除部分3和2,

然后将1保存为0部分

''更改其Multipart字段为False并返回给调用者。

如果NumRows> = 2那么

''请记住,行实际上从零开始编号

所以第一行是Dt.Rows(0)

对于n = 1到(NumRows - 1)

DT.Rows(n).Delete()

下一页

Application.DoEvents()

DT.Rows(0).Item(" Multipart")= False

IA.IsMultiPart = False

DT.Rows(0).Item(" PartPaymentNumber")= 0

IA.CurrentPartNumber = 0


Else''Numrows必须为1,即DT.Rows(0)

DT.Rows(0).Item(" Multipart")= False

IA.IsMultiPart = False

DT.Rows(0).Item(" PartPaymentNumber")= 0

IA.CurrentPartNumber = 0

结束如果

''最后更新数据库

DA.Update(DT)

结束如果


''收拾好

DA.Dispose()

DT.Dispose()

CB.Dispose()

Cn.Close()

StrSQL =没什么


''更新列表

PopulateInvoiceList(InvNum)


Catch等......


重建列表部分:

PopulateInvoiceList(InvNum)子程序只使用传递的

InvNum重建列表,以确定要突出显示哪一个。它使用以下db调用:


Dim StrSQL As String,Dr As OleDb.OleDbDataReader,Cmd As

OleDb.OleDbCommand,Str As String,n As整数

Dim SelItem As Integer,TempStr As String,cn As

OleDb.OleDbConnection


尝试


StrSQL ="从发票中选择*,其中fkCustomerID =" &

CurrentClientID& " ORDER BY [Invoice Number] Desc,PartPaymentNumber;"

cn = New OleDb.OleDbConnection(DefCon& DBFilePath)''DefCon和

DBfile路径只是构建连接字符串。

cn.Open()

Cmd =新OleDb.OleDbCommand(StrSQL,Conn)

Dr = Cmd.ExecuteReader

lstInvoices.Iles.Clear()


如果不是Dr.HasRows那么

''没有找到该客户的发票

''收拾好

Dr.Close()

Cmd.Dispose()

Dr = Nothing

Cmd =没什么

StrSQL =没什么

退出Sub

结束如果


做Dr.Read

Str =格式(博士(发票编号))''必须有一个

这些''' sa required field

lstInvoices.Items.Add(Str)''将其推入列表中

TempStr + = Str


Str =格式(Dr(PartPaymentNumber),000)

lstInvoices.Ite ms(n).SubItems.Add(Str)

TempStr + ="," &安培; Str


如果不是IsDBNull(Dr(注1))那么

Str = Dr(注1)

结束如果


如果不是IsDBNull(Dr(注2))那么

如果Str =""然后

Str = Dr(注2)

否则

Str + ="," &安培;博士(注2)

结束如果

结束如果

TempStr + ="," &安培; Str


lstInvoices.Items(n).SubItems.Add(Str)

''MsgBox(TempStr,MsgBoxStyle.Information," Siv Testing")

TempStr =""


''如果要求选择某个项目,请在此处检查

并且

''存储索引,所以最后我们可以突出显示那个。

If(Dr(" Invoice Number")= InvNum)和

(博士(PartPaymentNumber)= PartNum)然后


''我们正在通过一个选择

SelItem = n


结束如果

n + = 1


循环


''如果未找到匹配项,则selitem = 0或列表中的第一项

如果lstInvoices.Items.Count> 0然后


lstInvoices.Items(SelItem).Selected = True


如果SelItem = 0那么

' '获取该项目的InvNum

InvNum = GetSelectedInvoiceNumber()''如果我们没有
通过一个发票编号来选择,系统就会找出发票的内容

ID来自列表并显示。

PartNum = GetSelectedPartNumber()''同上零件编号

如果它是多部分发票。

结束如果


PopulateInvoice(InvNum,False,PartNum)''此调用然后

更新主要部分屏幕反映了

列表中的所选项目。


结束如果


''整理

Dr.Close()

Cmd.Dispose()

Dr = Nothing

Cmd = Nothing

StrSQL = Nothing


我尝试为DataAdapter创建一个RowUpdated处理程序,但是

只是触发,我在尝试时仍会出错画出清单。

这让我很生气!!


-

Siv

Martley,英国伍斯特附近。

Hi,
I seem to be having a problem with a DataAdapter against an Access database.
My app deletes 3 records runs a da.update(dt) where dt is a data.Datatable.
I then proceed to update a list to reflect that the 3 items have been
deleted only to discover that the 3 items appear, however when I click on
them to display their information which runs a datareader over the same
database it appears that the data has now gone.

I wondered whether this is a timing issue, I tried inserting a timer that
waited for half a second and then updated the list but it still doesn''t
work.
If I exit the form that all this is running on (it''s an MDI app, so I don''t
close the application) then re-open it (creates a new instance), the list is
fine and reflect the fact that the 3 items have been deleted??

Anyone know why I am geting this grief?

Essentially the code is:
The deletion part:

Dim CB As OleDb.OleDbCommandBuilder, DT As Data.DataTable, DA As
OleDb.OleDbDataAdapter
Dim StrSQL As String, Cn As OleDb.OleDbConnection
Dim NumRows As Integer, n As Integer

Try
StrSQL = "Select * from Invoices where [Invoice Number] = " &
InvNum & "AND DeletedYN=False ORDER BY PartPaymentNumber desc;"
Cn = New OleDb.OleDbConnection(DefCon & DBFilePath)
Cn.Open()
DA = New OleDb.OleDbDataAdapter(StrSQL, Cn)
DT = New Data.DataTable
CB = New OleDb.OleDbCommandBuilder(DA)
CB.QuotePrefix = "["
CB.QuoteSuffix = "]"
DA.Fill(DT)

NumRows = DT.Rows.Count
If NumRows > 0 Then
''We have some records
''The records will be in part number reverse order ie, if a 3
parter, it will
''be 3,2,1. We can delete from the database parts 3 and 2,
and then save 1 as part 0
''Change its "Multipart" field to False and return to caller.
If NumRows >= 2 Then
''Remember that the rows are actually numbered from zero
so 1st row is Dt.Rows(0)
For n = 1 To (NumRows - 1)
DT.Rows(n).Delete()
Next
Application.DoEvents()
DT.Rows(0).Item("Multipart") = False
IA.IsMultiPart = False
DT.Rows(0).Item("PartPaymentNumber") = 0
IA.CurrentPartNumber = 0

Else ''Numrows must be 1, ie DT.Rows(0)
DT.Rows(0).Item("Multipart") = False
IA.IsMultiPart = False
DT.Rows(0).Item("PartPaymentNumber") = 0
IA.CurrentPartNumber = 0
End If
''Finally update the database
DA.Update(DT)
End If

''Tidy up
DA.Dispose()
DT.Dispose()
CB.Dispose()
Cn.Close()
StrSQL = Nothing

''update the list
PopulateInvoiceList(InvNum)

Catch etc ...

The rebuild teh list part:
The PopulateInvoiceList(InvNum) sub just rebuilds the list using the passed
InvNum to identify which one to highlight. It uses the follwoing db calls:

Dim StrSQL As String, Dr As OleDb.OleDbDataReader, Cmd As
OleDb.OleDbCommand, Str As String, n As Integer
Dim SelItem As Integer, TempStr As String, cn As
OleDb.OleDbConnection

Try

StrSQL = "Select * from Invoices where fkCustomerID = " &
CurrentClientID & " ORDER BY [Invoice Number] Desc, PartPaymentNumber;"
cn = New OleDb.OleDbConnection(DefCon & DBFilePath) ''DefCon and
DBfile path just build the connection string.
cn.Open()
Cmd = New OleDb.OleDbCommand(StrSQL, Conn)
Dr = Cmd.ExecuteReader

lstInvoices.Items.Clear()

If Not Dr.HasRows Then
''No Invoices found for this customer
''Tidy Up
Dr.Close()
Cmd.Dispose()
Dr = Nothing
Cmd = Nothing
StrSQL = Nothing
Exit Sub
End If

Do While Dr.Read
Str = Format(Dr("Invoice Number")) ''There has to be one of
these as it''s a required field
lstInvoices.Items.Add(Str) ''Push it into the list
TempStr += Str

Str = Format(Dr("PartPaymentNumber"), "000")
lstInvoices.Items(n).SubItems.Add(Str)
TempStr += ", " & Str

If Not IsDBNull(Dr("Note 1")) Then
Str = Dr("Note 1")
End If

If Not IsDBNull(Dr("Note 2")) Then
If Str = "" Then
Str = Dr("Note 2")
Else
Str += ", " & Dr("Note 2")
End If
End If
TempStr += ", " & Str

lstInvoices.Items(n).SubItems.Add(Str)
''MsgBox(TempStr, MsgBoxStyle.Information, "Siv Testing")
TempStr = ""

''If an item has been requested to be selected then check for
it here and
''store the index so at the end we can highlight that one.
If (Dr("Invoice Number") = InvNum) And
(Dr("PartPaymentNumber") = PartNum) Then

''We are passing the one to select
SelItem = n

End If
n += 1

Loop

''If no match found, then selitem = 0 or first item in list
If lstInvoices.Items.Count > 0 Then

lstInvoices.Items(SelItem).Selected = True

If SelItem = 0 Then
''Get the InvNum for that item
InvNum = GetSelectedInvoiceNumber() ''If we haven''t
passed an Invoice number to select, system just works out what the Invoice
ID is from the list and shows that.
PartNum = GetSelectedPartNumber() ''Ditto the part number
if it''s a multipart invoice.
End If

PopulateInvoice(InvNum, False, PartNum) ''This call then
updates teh main part of the screen to reflect the selected item in the
list.

End If

''Tidy Up
Dr.Close()
Cmd.Dispose()
Dr = Nothing
Cmd = Nothing
StrSQL = Nothing

I have tried creating a RowUpdated handler for the DataAdapter, but that
just fires and I still get errors when trying to draw the list.
It''s driving me mad!!

--
Siv
Martley, Near Worcester, UK.

推荐答案

Siv,


我的主要部分对我来说不清楚的是你是如何构建那个列表的。

(因为我假设在你再次开始阅读之后,dataadapter.update会删除这些行) br />

你说你正在使用3次传球。而且我有一个想法,我只看到2.


除此之外,知道在你的代码中所有这些设置都没有,并且

处理什么都不做。

唯一重要的是你的连接和datareader关闭

和/或处理。


我不是看看问题,但也许你可以展示或告诉你的意思

with。
Siv,

The main part for me that is not clear for me is how you built that list.
(Because I assume that the rows are deleted by the dataadapter.update before
you start reading again)

You say that you are using 3 passes. And I have the idea that I only see 2.

Beside that, know that in your code all those settings to nothing and
disposing do nothing.
The only thing that can is important is your connection and datareader close
and/or dispose.

I don''t see the problem, however maybe can you show or tell what you mean
with.
重建列表部分:
PopulateInvoiceList(InvNum )sub只是使用
传递的InvNum来重建列表,以识别要突出显示的列表。它使用以下的数据来调用:
The rebuild teh list part:
The PopulateInvoiceList(InvNum) sub just rebuilds the list using the
passed InvNum to identify which one to highlight. It uses the follwoing
db calls:




这是关于第二部分还是第二部分?


Cor



Is this about the second or the thirth part?

Cor


Cor,

最初在表单加载时绘制列表,它获取客户ID

然后只列出所有与该客户有关系链接

链接的相应发票。

您在我的初始帖子中有相应的代码。我基本上在发票表上打开一个

datareader,使用一个SQL字符串将行限制为

只是与表格所显示的发票的客户相关的行。


listview控件(lstInvoices)有多个列,其中一列

包含发票编号,这是发票表的关键字段。当用户点击列表时,包含发票号的列用于

调用另一个填充屏幕的例程。这被称为

" PopulateInvoice" (它只是使用

相关的发票数据更新屏幕上的所有文本框),它使用datareader获取信息,并且它会更新屏幕。

更新屏幕。


然后用户决定要修改所选的发票(发票可以

有多个部分,它们都有相同的发票号,但不同的

部件号,这两个字段包含一个唯一的键)。发票可以存在

作为单件发票,其中有一条记录,零件号是零b / b,或者它们可以是多部分发票,其中有多条记录全部

,发票编号相同但部件号不同。


我的问题是多部分发票,我想要实现的是

用户可以将多部分转换为单个部分。这是通过

用户单击按钮将多部分转换为单个部分来实现的。然后打开

为给定的多部分发票号码保留的所有记录。让我们说它的

发票123有3个部分,所以记录是


发票编号|零件编号

123 | 001

123 | 002

123 | 003


我调用的第一个例程显示了使用发票编号作为查询基础的

命令构建器打开数据适配器。使用DataAdapter和DataTable检索

得到的3条记录。我

然后删除记录123-003和123-002,然后我修改剩余的

记录123-001,以便零件号字段设置为000并设置一个标志

field" MultiPartYN"为假,然后要求DA更新DT:

DA.Fill(DT)。当我这样做时,我希望数据库已经删除

两条记录123-002和123-003如果我在MS Access中查看它们

它们现在是已删除,所以我知道DataAdapter正在进行更新。


整理我的vars后的最后一步(感谢您的评论不要

需要设置一切都是Nothing)是召回UpdateInvoiceList

例程,这是通过发票编号123(只有这样我才能确保

,当列表突出显示123记录被重建)。

UpdateInvoicelist完全清除列表然后使用DataReader根据客户编号再次获取客户的所有发票

a小子程序,监视每个正在检索的记录,如果它与b * b $ b匹配传递的发票编号123,它将位置存储在列表中,所以

在流程结束时我可以将选择设置到该项目上。


应该发生的是,旧记录123-002和123-003现在应该不会出现,因为它们不会出现已被删除,实际发生的是

DataReader仍然找到旧记录并将它们放入列表中。如果

重建列表显示这些旧的已删除记录,我点击其中一个

看看会发生什么我在PopulateInvoices例程中得到一个例外

填充所有文本框,因为它正确地发现这两个记录

不存在!?


我发现如果我在代码中放一个细分并手动步进它就像预期的那样工作,但是如果我让它正常运行它总是出错并且总是把

删除的记录放到列表中。


Aggghhhh!


Siv


-

Siv

Martley,英国伍斯特附近。

Cor Ligthert <无************ @ planet.nl>在消息中写道

news:eJ ************** @ tk2msftngp13.phx.gbl ...
Cor,
The list is drawn initially when the form loads, it obtains a customer ID
and then just lists all the corresponding invoices that have a relational
link to that customer.
You have the code for that in my initial post. I basically open a
datareader on the invoices table using an SQL string to limit the rows to
just those relating to the customer whose invoices the form is displaying.

The listview control (lstInvoices) has a number of columns, one of which
holds the Invoice Number which is the key field of the Invoices table. When
the user clicks the list the column containing the invoice number is used to
call another routine that populates the screen. This is called
"PopulateInvoice" (it just updates all the textboxes on the screen with the
relevant invoice data), it uses a datareader to get the information and it
updates the screen.

The user then decides they want to modify the selected Invoice (Invoices can
have multiple parts, they all have the same invoice number, but different
part numbers, the two fields comprise a unique key). The invoices can exist
as single part invoices where there is one record and the part number is
zero, or they can be multipart invoices where there are multiple records all
with the same invoice number but different part numbers.

My problem is with the multipart invoices, what I am trying to achieve is
that the user can convert a multipart to a single. This is achieved by the
user clicking a button to convert from multipart to single. It then opens
all the records held for a given multipart invoice number. Let''s say its
invoice 123 with 3 parts, so the records are

Invoice Number | Part Number
123 | 001
123 | 002
123 | 003

I call the first routine is showed which opens a data adapter with a
commandbuilder using the Invoice Number as the basis of the query. The
resulting 3 records are retrieved with the DataAdapter and DataTable. I
then delete the records 123-003 and 123-002, I then modify the remaining
record 123-001 so that the Part Number field is set to 000 and set a flag
field "MultiPartYN" to false and then ask DA to update DT with :
DA.Fill(DT). When I have done that I expect the database to have deleted
the two records 123-002 and 123-003 which if I look at them in MS Access
they now are deleted, so I know the DataAdapter is doing the update.

The final step after tidying up my vars (Thanks for your comment about not
needing to set everything to Nothing) is to recall the UpdateInvoiceList
routine, this is passed the Invoice number 123 (only so that I can ensure
that the 123 record is highlighted when the list is rebuilt). The
UpdateInvoicelist clears the list completely then uses a DataReader to get
all the Invoices for the customer again based on the Customer Number, I have
a little subroutine that watches each record being retrieved and if it
matches the passed Invoice Number 123 it stores the position in the list so
that at the end of the process I can set the selection onto that item.

What should happen is that the old records 123-002 and 123-003 should now
not be present as they have been deleted, what actually happens is that the
DataReader still finds the old records and puts them in the list. If when
the list is rebuilt showing these old deleted records I click on one of them
to see what happens I get an exception in my PopulateInvoices routine which
fills all the text boxes, because it correctly finds that these two records
don''t exist!?

I have found if I put a break in the code and step it manually it works as
expected, but if I let it run normally it always errors and always puts the
deleted records into the list.

Aggghhhh!

Siv

--
Siv
Martley, Near Worcester, UK.
"Cor Ligthert" <no************@planet.nl> wrote in message
news:eJ**************@tk2msftngp13.phx.gbl...
Siv,
我不熟悉的主要部分是你如何构建该列表。
(因为我假设在你再次开始阅读之前,dataadapter.update会删除这些行


你说你正在使用3次传球。并且我有一个想法,我只看到
2.

除此之外,知道在你的代码中所有这些设置都没有,并且
处理什么都不做。
唯一重要的是你的连接和datareader
关闭和/或处置。

我没有看到问题,但是你可以展示或说出你的意思吗? /> with。
Siv,

The main part for me that is not clear for me is how you built that list.
(Because I assume that the rows are deleted by the dataadapter.update
before you start reading again)

You say that you are using 3 passes. And I have the idea that I only see
2.

Beside that, know that in your code all those settings to nothing and
disposing do nothing.
The only thing that can is important is your connection and datareader
close and/or dispose.

I don''t see the problem, however maybe can you show or tell what you mean
with.
重建列表部分:
PopulateInvoiceList(InvNum)子程序只使用
传递的InvNum重建列表以识别要突出显示的列表。它使用了以下的db调用:
The rebuild teh list part:
The PopulateInvoiceList(InvNum) sub just rebuilds the list using the
passed InvNum to identify which one to highlight. It uses the follwoing
db calls:



这是关于第二部分还是第二部分?

Cor



Is this about the second or the thirth part?

Cor



哎呀在我的回复中犯了错误?我的第六段应该是:


我调用第一个例程,它打开一个带有
Whoops made a mistake in my reply? My sixth paragraph should read:

I call the first routine is showed which opens a data adapter with a
commandbuilder的数据适配器,使用Invoice Number作为基础。查询。使用DataAdapter和DataTable检索
得到的3条记录。我
然后删除记录123-003和123-002,然后我修改剩余的
记录123-001,以便零件号字段设置为000并设置一个标志
字段" ; MultiPartYN"为假,然后要求DA更新DT:****
DA.UPDATE(DT)。 *****当我这样做时,我希望数据库已经删除了两条记录123-002和123-003,如果我在MS中查看它们,那么它们现在会被删除,所以我知道DataAdapter正在进行更新。



-

Siv

Martley,英国伍斯特附近。

"西夫" < MS ********** @ removeme.sivill.com>在消息中写道

新闻:uD ************** @ TK2MSFTNGP15.phx.gbl ... Cor,
该列表最初是在表格加载,它获得一个客户ID
然后只列出所有与该客户有关系链接的相应发票。
您在我的初始帖子中有相应的代码。我基本上在发票表上打开一个
datareader,使用SQL字符串将行限制为与表单所显示的发票的客户相关的行。

listview控件(lstInvoices)有多个列,其中一列
包含发票编号,这是发票表的关键字段。
当用户点击列表时,包含发票编号的列是
用于调用填充屏幕的另一个例程。这被称为
PopulateInvoice。 (它只是用相关的发票数据更新屏幕上的所有文本框),它使用datareader获取信息
并更新屏幕。

用户然后决定他们想要修改所选的发票(发票
可以有多个部分,它们都有相同的发票号,但是不同的部件号,这两个字段包含一个唯一的键)。
发票可以作为单个部分发票存在,其中有一个记录和部件号为零,或者它们可以是多部分发票,其中有多个记录都具有相同的发票号但是不同的部分
数字。

我的问题是多部分发票,我想要实现的是用户可以将多部分转换为单个部分。这是通过用户点击按钮将多部分转换为单个部分来实现的。然后它打开为给定的多部分发票号码保存的所有记录。让我们说它的发票123有3个部分,所以记录是

发票编号|零件编号
123 | 001
123 | 002
123 | 003

我调用的第一个例程显示了使用Invoice Number作为查询基础的
命令构建器打开数据适配器。使用DataAdapter和DataTable检索
得到的3条记录。我
然后删除记录123-003和123-002,然后我修改剩余的
记录123-001,以便零件号字段设置为000并设置一个标志
字段" ; MultiPartYN"为假,然后要求DA更新DT:
DA.Fill(DT)。当我这样做时,我希望数据库已经删除了两条记录123-002和123-003,如果我在MS Access中查看它们,它们现在被删除了,所以我知道DataAdapter是做更新。

整理我的vars之后的最后一步(感谢您关于不需要将所有内容设置为Nothing的评论)是回想一下UpdateInvoiceList
例程,这个通过发票编号123(仅限于我可以确保重建列表时突出显示123记录)。
UpdateInvoicelist完全清除列表,然后使用DataReader根据客户编号再次获取客户的所有发票,我有一个小子程序,可以查看正在检索的每个记录,如果
它匹配传递的发票编号123,它将位置存储在
列表中,以便在流程结束时我可以将选择设置到该
项目上。
应该发生的是,旧记录123-002和123-003现在应该不存在,因为它们已被删除,实际发生的是DataReader仍然找到旧记录并放置它们在列表中。如果
重建列表时显示这些旧的已删除记录,我点击其中的一个,看看会发生什么,我在填充所有文本框的PopulateInvoices
例程中得到一个例外,因为它正确地发现
这两个记录不存在!?

我发现如果我在代码中中断并手动步骤它会像
预期的那样工作,但是如果我让它正常运行它总是出错并且总是将已删除的记录放入列表中。

高亮!

Siv

-
Siv
Martley,英国伍斯特附近。
Cor Ligthert <无************ @ planet.nl>在消息中写道
新闻:eJ ************** @ tk2msftngp13.phx.gbl ...
commandbuilder using the Invoice Number as the basis of the query. The
resulting 3 records are retrieved with the DataAdapter and DataTable. I
then delete the records 123-003 and 123-002, I then modify the remaining
record 123-001 so that the Part Number field is set to 000 and set a flag
field "MultiPartYN" to false and then ask DA to update DT with : ****
DA.UPDATE(DT). ***** When I have done that I expect the database to have
deleted the two records 123-002 and 123-003 which if I look at them in MS
Access they now are deleted, so I know the DataAdapter is doing the
update.

--
Siv
Martley, Near Worcester, UK.
"Siv" <ms**********@removeme.sivill.com> wrote in message
news:uD**************@TK2MSFTNGP15.phx.gbl... Cor,
The list is drawn initially when the form loads, it obtains a customer ID
and then just lists all the corresponding invoices that have a relational
link to that customer.
You have the code for that in my initial post. I basically open a
datareader on the invoices table using an SQL string to limit the rows to
just those relating to the customer whose invoices the form is displaying.

The listview control (lstInvoices) has a number of columns, one of which
holds the Invoice Number which is the key field of the Invoices table.
When the user clicks the list the column containing the invoice number is
used to call another routine that populates the screen. This is called
"PopulateInvoice" (it just updates all the textboxes on the screen with
the relevant invoice data), it uses a datareader to get the information
and it updates the screen.

The user then decides they want to modify the selected Invoice (Invoices
can have multiple parts, they all have the same invoice number, but
different part numbers, the two fields comprise a unique key). The
invoices can exist as single part invoices where there is one record and
the part number is zero, or they can be multipart invoices where there are
multiple records all with the same invoice number but different part
numbers.

My problem is with the multipart invoices, what I am trying to achieve is
that the user can convert a multipart to a single. This is achieved by
the user clicking a button to convert from multipart to single. It then
opens all the records held for a given multipart invoice number. Let''s
say its invoice 123 with 3 parts, so the records are

Invoice Number | Part Number
123 | 001
123 | 002
123 | 003

I call the first routine is showed which opens a data adapter with a
commandbuilder using the Invoice Number as the basis of the query. The
resulting 3 records are retrieved with the DataAdapter and DataTable. I
then delete the records 123-003 and 123-002, I then modify the remaining
record 123-001 so that the Part Number field is set to 000 and set a flag
field "MultiPartYN" to false and then ask DA to update DT with :
DA.Fill(DT). When I have done that I expect the database to have deleted
the two records 123-002 and 123-003 which if I look at them in MS Access
they now are deleted, so I know the DataAdapter is doing the update.

The final step after tidying up my vars (Thanks for your comment about not
needing to set everything to Nothing) is to recall the UpdateInvoiceList
routine, this is passed the Invoice number 123 (only so that I can ensure
that the 123 record is highlighted when the list is rebuilt). The
UpdateInvoicelist clears the list completely then uses a DataReader to get
all the Invoices for the customer again based on the Customer Number, I
have a little subroutine that watches each record being retrieved and if
it matches the passed Invoice Number 123 it stores the position in the
list so that at the end of the process I can set the selection onto that
item.

What should happen is that the old records 123-002 and 123-003 should now
not be present as they have been deleted, what actually happens is that
the DataReader still finds the old records and puts them in the list. If
when the list is rebuilt showing these old deleted records I click on one
of them to see what happens I get an exception in my PopulateInvoices
routine which fills all the text boxes, because it correctly finds that
these two records don''t exist!?

I have found if I put a break in the code and step it manually it works as
expected, but if I let it run normally it always errors and always puts
the deleted records into the list.

Aggghhhh!

Siv

--
Siv
Martley, Near Worcester, UK.
"Cor Ligthert" <no************@planet.nl> wrote in message
news:eJ**************@tk2msftngp13.phx.gbl...
Siv,
我不熟悉的主要部分是你如何构建该列表。
(因为我假设在再次开始阅读之前,dataadapter.update会删除这些行)/ br / >
你说你正在使用3次传球。并且我有一个想法,我只看到
2.

除此之外,知道在你的代码中所有这些设置都没有,并且
处理什么都不做。
唯一重要的是你的连接和datareader
关闭和/或处置。

我没有看到问题,但是你可以展示或说出你的意思吗? /> with。
Siv,

The main part for me that is not clear for me is how you built that list.
(Because I assume that the rows are deleted by the dataadapter.update
before you start reading again)

You say that you are using 3 passes. And I have the idea that I only see
2.

Beside that, know that in your code all those settings to nothing and
disposing do nothing.
The only thing that can is important is your connection and datareader
close and/or dispose.

I don''t see the problem, however maybe can you show or tell what you mean
with.
重建列表部分:
PopulateInvoiceList(InvNum)子程序只使用
传递的InvNum重建列表以识别要突出显示的列表。它使用了以下的db调用:
The rebuild teh list part:
The PopulateInvoiceList(InvNum) sub just rebuilds the list using the
passed InvNum to identify which one to highlight. It uses the follwoing
db calls:



这是关于第二部分还是第二部分?

Cor



Is this about the second or the thirth part?

Cor




这篇关于帮助 - 问题让DataAdapter更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆