Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

record did not update the table

Status
Not open for further replies.

yan19454

MIS
May 19, 2005
94
US
If LabOutConnection.State = ConnectionState.Closed Then
LabOutConnection.Open()
End If



Dim sqlStr As String = "select * from NewImportLabChar where Mid([NewImportLabChar]![LabResultString],1,1)='>' or Mid([NewImportLabChar]![LabResultString],1,1)='<' "
Dim dsLab As New DataSet
Dim da As New OleDbDataAdapter



da.SelectCommand = New OleDbCommand(sqlStr, LabOutConnection)
da.SelectCommand.Connection = LabOutConnection
da.SelectCommand.CommandType = CommandType.Text
da.Fill(dsLab, "NewImportLabChar")

Dim drLab As DataRow

Dim intRow As Int16
For Each drLab In dsLab.Tables("NewImportLabChar").Rows
drLab = dsLab.Tables("NewImportLabChar").Rows(intRow)
drLab.BeginEdit()
drLab("LabResult") = GetLabValue(drLab("LabResultString"))

Debug.Print(GetLabValue(drLab("LabResultString")))
drLab.AcceptChanges()

Next
dsLab.Tables("NewImportLabChar").AcceptChanges()
da.Update(dsLab, "NewImportLabChar")
MessageBox.Show(da.Update(dsLab, "NewImportLabChar").ToString)
da.Dispose()

I looped through the datarow and run the application without error. but the record number update is zero.
 
Do not update the datarow before the da.Update is executed.
drLab.AcceptChanges() should be removed.

If you are going to continue updating the datatable, then
put dsLab.AcceptChanges after da.Update(dsLab, "NewImportLabChar")

Regards.
 
If LabOutConnection.State = ConnectionState.Closed Then
LabOutConnection.Open()
End If
Dim sqlStr As String = "select * from NewImportLabChar where Mid([NewImportLabChar]![LabResultString],1,1)='>' or Mid([NewImportLabChar]![LabResultString],1,1)='<' "
Dim dsLab As New DataSet
Dim da As New OleDbDataAdapter
da.SelectCommand = New OleDbCommand(sqlStr, LabOutConnection)
da.SelectCommand.Connection = LabOutConnection
da.SelectCommand.CommandType = CommandType.Text
da.Fill(dsLab, "NewImportLabChar")
Dim drLab As DataRow
'strS = drLab("LabResultString")
' ' Dim intRow As Int16
For Each drLab In dsLab.Tables("NewImportLabChar").Rows
drLab = dsLab.Tables("NewImportLabChar").Rows(intRow)
Try
' Dim cmd As New OleDbCommandBuilder(da)
' Debug.Print(drLab("PNO"))
drLab.BeginEdit()
Debug.Print(drLab("InternalID").ToString)
If drLab("LabCode") = "MB" Or drLab("LabCode") = "CPK" Then
'as whole number
drLab("LabResult") = GetWLabValue(drLab("LabResultString"))
Else
drLab("LabResult") = GetLabValue(drLab("LabResultString"))
End If
' drLab.AcceptChanges()
Catch e As Exception
MessageBox.Show(e.Message)
End Try

Next
da.Update(dsLab, "NewImportLabChar")
dsLab.Tables("NewImportLabChar").AcceptChanges()
MessageBox.Show(da.Update(dsLab, "NewImportLabChar").ToString)
da.Dispose()
I did the change. but I still get the datarow update is 0.
data is not update.
In Debug.Print(drLab("InternalID").ToString)it only print out one row and did not move to different record.but it loop through the record.
 
Would it be bad idea/wrong, instead of these to use an update sql stament? Something like this for example?

sql = "update NewImportLabChar set labResultString=something where Mid([NewImportLabChar]![LabResultString],1,1)='>' or Mid([NewImportLabChar]![LabResultString],1,1)='<'"

Command = New SqlCommand(sql, MyConn)
' Execute the command.
Dim NumAffected As Integer
NumAffected = Command.ExecuteNonQuery()
 
do not know why it did not update. the datarow count is 276. the string in query can return
select * from NewImportLabChar where Mid([NewImportLabChar]![LabResultString],1,1)='>' or Mid([NewImportLabChar]![LabResultString],1,1)='<' return 276 record ,too.

but one thing is strange is Debug.Print(drLab("InternalID").ToString) just print out the first row of the datarow 276 times.

Thx.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top