如何保持datarow是DataRowState.Added
发表于:2007-06-30来源:作者:点击数:
标签:
大多数情况下,我们希望从 数据库 读出的DataSet中的每个DataRow为DataRowState.UnChanged状态。 但是在表的同步情况下,我们希望DataRow的状态为DataRowState.Added. 这个很容易被实现: 你可以设置SqlDataAdapter对象的AcceptChangesDuringFill属性为False
大多数情况下,我们希望从
数据库读出的DataSet中的每个DataRow为DataRowState.UnChanged状态。
但是在表的同步情况下,我们希望DataRow的状态为DataRowState.Added.
这个很容易被实现:
你可以设置SqlDataAdapter对象的A
clearcase/" target="_blank" >cceptChangesDuringFill属性为False.
这样,读出来的表的DataRow的状态就是DataRowState.Added.
下面是个例子:
Public Function GetLogTables(sHostIP As String, _
sTableName As String, _
dLastUpdate As Date) As DataSet
Dim oConn As SqlConnection
Try
@# create new DataSet and create array of table names
Dim oDS As New DataSet("IISLogResult")
@# create Connection and DataAdapter with empty
@# SelectCommand text
oConn = New SqlConnection( _
ConfigurationSettings.AppSettings("IISLogs"))
Dim oDA As New SqlDataAdapter("", oConn)
@#rows must be marked as "added"
oDA.AcceptChangesDuringFill = False
oConn.Open()
@# change the SQL statement by setting the
@# CommandText property of the Command object
@# a
lready attached to the DataAdapter
oDA.SelectCommand.CommandText = “SELECT * FROM ” sTableName.Trim()
@# fill this table in the DataSet
oDA.Fill(oDS, sTableName.Trim())
Return oDS @# and return the DataSet to the client
Finally
oConn.Close()
End Try
End Function
原文转自:http://www.ltesting.net