andycharger
Well-known member
- Joined
- Apr 2, 2003
- Messages
- 152
Hi,
Im building an application that cycles through records in an access database and applies a check on the data. If it is not compliant, it sticks a row_id and error message into a table called "errors"
However, When there is more than one error (i.e, there is multiple error results) the sql statemt seems to fail.
Here is my code.
ThestrNewSql that is output lookslike this:
Anyone got any ideas?
Im building an application that cycles through records in an access database and applies a check on the data. If it is not compliant, it sticks a row_id and error message into a table called "errors"
However, When there is more than one error (i.e, there is multiple error results) the sql statemt seems to fail.
Here is my code.
Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim strNewSql As String
Dim strID As Integer
Dim i As Integer
Dim strDSN As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\lynda.mdb"
Dim strSQL As String = "SELECT * FROM HBMID"
create Objects of ADOConnection and ADOCommand
Dim myConn As New OleDbConnection(strDSN)
Dim myConn2 As New OleDbConnection(strDSN)
Dim myCmd As New OleDbCommand(strSQL, myConn)
Dim strItem As String
Dim datareader As OleDbDataReader = Nothing
myConn.Open()
datareader = myCmd.ExecuteReader()
i = 0
While datareader.Read()
i = i + 1
permitted driver rules
check for Insured and Named Drivers or Ex Under 25 years O/T
If datareader("field9") = "7" Or datareader("field9") = "N" Then
they must be conditon "2". Check this
If datareader("field19") = "2" Then
do nothing
ListBox1.Items.Add(datareader("field6"))
Else
must have the wrong code. Put them in the errors list.
strNewSql = strNewSql + " Insert into Errors (row_id, error_text) Values (" & i & ",Column S should be 2); "
End If
Else
ok so they are not N or 7.
End If
End While
myConn.Close()
check there are errors
If strNewSql = "" Then
do nothing
Else
open the connection
myConn2.Open()
Dim MyCmd2 As New OleDbCommand(strNewSql, myConn2)
myCmd2.ExecuteNonQuery()
myConn2.Close()
End If
End Sub
ThestrNewSql that is output lookslike this:
Code:
strNewSql " Insert into Errors (row_id, error_text) Values (6,Column S should be 2); Insert into Errors (row_id, error_text) Values (117,Column S should be 2); "
Anyone got any ideas?