?? ????? ????? ????
CommandBuilder ??? ?????? ????? ????? ??????? ?????? ??? ???????
DataAdapter.Update ?? ?? ??? ????? ????????? ??? ?????. ???? ??? ??????? ??????? ???????:
- ??? ??? ??? ????? ???? CommandBuilder ???? DataAdapter.
- ??? ??????? ??????? GetInsertCommand ?? GetUpdateCommandGetDeleteCommand ?????? CommandBuilder ?????? ????? DataAdapter ???? ????.
- ??? ??? ?????? ??? ??????? ???? ???? CommandBuilder.
??? ?????? ??????? ???????
?????DataAdapter ?? ????? ????? ????? ???????:
??? ??????? ??? ????? ?? ????? 'System.Data.SqlClient.SqlException' ?? system.data.dll
???? ??? ??????? ???? ?????
CommandBuilder ???? ???? ??? ??????? ???? ???? ??? ???? ??? ????? ??????.
??? ??? ??????? ?????? ???? ????? ???????:
- ?? ??? ?????? ??????? ???? ???? CommandBuilder. ?? ???? CommandBuilder ???????? ??????? ????? ?????.
- ???? ?????? InsertCommand ? DeleteCommandUpdateCommand ???? DataAdapter (???? ??? "???? ?? ?????????" ?????? ??? ????). ??? ?? ???? ????? DataAdapter ???? ?? ??? ?????? ?? ???? ?????? DataAdapter ??????.
- ??? ??????? CommandBuilder ???????. ????? ?????? ??????? ????? ?? ?? ??????? "????? ???????? ?????" ??? ???????.
????? ??? ?????? ??? ???????.
????? ????? ????? ?? ????
- ????? ????? Visual Basic ????? Windows ????. ??? ????? Form1 ??? ??????? ???? ???????.
- ???? ????? ??????? ??? ??????? ?? ?? ?????? ????????? ???????? ??????? ?? ????? ?????? ?? ???? ????????? ????????:
Imports System.Data.SqlClient
- ????? ???? ???? ?? ??? Form1.
- ???? ????? ??????? ??? ???? ?? ?? ?????? ????????? ???????? ??????? ??? ????? ????:
Dim cn As New SqlConnection()
Dim custDS As New DataSet()
Dim da1 As New SqlDataAdapter()
Dim da2 As New SqlDataAdapter()
Dim dr As DataRow
Dim cb As SqlCommandBuilder
cn.ConnectionString = "server=servername;database=northwind;uid=sa;pwd=password;"
cn.Open()
da1 = New SqlDataAdapter("select * from Customers", cn)
cb = New SqlCommandBuilder(da1)
da1.Fill(custDS, "Customers")
'Get the original commands.
da1.InsertCommand = cb.GetInsertCommand
da1.DeleteCommand = cb.GetDeleteCommand
da1.UpdateCommand = cb.GetUpdateCommand
Debug.WriteLine("Original command length: " & da1.InsertCommand.CommandText.Length)
'Modify the Insert command.
da1.InsertCommand.CommandText = "select * from customers where customerid=@@identity"
da1.InsertCommand.UpdatedRowSource = UpdateRowSource.FirstReturnedRecord
da2.InsertCommand = da1.InsertCommand
da2.DeleteCommand = da1.DeleteCommand
da2.UpdateCommand = da1.UpdateCommand
'Add a record to the table.
Dim tblCust As DataTable
tblCust = custDS.Tables("Customers")
Dim drCust As DataRow
drCust = tblCust.NewRow()
drCust("CustomerID") = "ZYYYY"
drCust("CompanyName") = "Zora's Yummies"
drCust("ContactName") = "Christophe Namby"
drCust("ContactTitle") = "Assistant Manager"
tblCust.Rows.Add(drCust)
'Update the backend.
Debug.WriteLine("Length da1 before insert: " & da1.InsertCommand.CommandText.Length)
da1.Update(custDS, "Customers")
Debug.WriteLine("Length da1 after insert: " & da1.InsertCommand.CommandText.Length)
Debug.WriteLine("length da2 before insert: " & da2.InsertCommand.CommandText.Length)
da2.Update(custDS, "Customers")
Debug.WriteLine("Length da2 after insert: " & da2.InsertCommand.CommandText.Length)
- ????? ????? ??????? ??????? ???????? Microsoft SQL Server.
- ???? ??????? F5 ?????? ????????? ????????.
- ????? ?????? ????? ?????? ??? ??? ???????:
da1.Update(custDS, "Customers")
???? ??? ???? ???
CommandBuilder ??? ?????
RowUpdating ???
DataAdapter ("da1") ???? ???? ??? ????? ???????. ??? ??? ??????? ??? ??????
DataAdapter ("da2")
CommandBuilder ?? ??? ??? ??? ??? ??????? ?????? ?? ?? ?? ???? ?????.
???? ??????? ????? ???? ??? "da1" ?
SqlCommandBuilder ("cb") ???????? ???? ?????? ??? ???? ???? ???????
CommandBuilder ????? ???????? ???
??? (??
????? ?? "Visual C" #). ????????? ?? ????? ??????? ??? ??????? ?? "da2." ??? ?? ???? ??????? ?? ????? ??????? ? ?? ??? ??????? ???????
da2.Update ????? NullReferenceException ??????.
???? ???????: 310366 - ????? ??? ??????: 15/?? ??????/1427 - ??????: 1.7
????? ???
- Microsoft ADO.NET 2.0
- Microsoft ADO.NET (included with the .NET Framework)
- Microsoft Visual Basic .NET 2002 Standard Edition
- Microsoft Visual Basic .NET 2003 Standard Edition
- Microsoft Visual Basic 2005
| kbmt kbtshoot kberrmsg kbprb kbsqlclient kbsystemdata KB310366 KbMtar |
????? ???????: ??? ????? ??? ?????? ???????? ?????? ????? ???? ????? ?????????? ????? ?? ????????? ?????? ????. ???? ???? ?????????? ???? ?? ???????? ???????? ?????? ????????? ????? ????????? ???????? ????? ???????? ?????? ?? ?????? ??? ?? ???????? ???????? ?? ????? ??????? ?????? ??? ??????? ?????? ??. ?????? ?? ???? ??? ??????? ???????? ????? ?? ???? ????? ?????? ??? ????? ??? ????? ??????? ?? ????? ?? ?????? ??? ??? ??????? ??????? ?? ????? ????? ????? ????? ?????. ?? ????? ???? ?????????? ??????? ??? ????? ?? ??????? ?? ????? ?????? ?? ??? ????? ?? ????? ??????? ?? ???????? ?? ??? ???????. ???? ???? ?????????? ???????? ??? ????? ?????? ??????? ??????
???? ??? ????? ??????? ?????? ??????????
310366
(http://support.microsoft.com/kb/310366/en-us/
)