J Trahair
Well-known member
Here is code to find all Blue T468's and to change their price to £16.50. This works fine.
If no Blue T468's are found, what is the equivalent to the old
'If rsRecordset.EOF = True Then' so I can add the INSERT INTO code?
PS. In the ObjDa.Fill(objDs, "xxx") and in the Dim cmd As New System.Data.OleDb.OleDbCommand("xxx", objConn) I have put 'xxx' as it doesn't seem to matter what that string is, or am I missing something?
Thanks for your patience!
Jonathan
If no Blue T468's are found, what is the equivalent to the old
'If rsRecordset.EOF = True Then' so I can add the INSERT INTO code?
PS. In the ObjDa.Fill(objDs, "xxx") and in the Dim cmd As New System.Data.OleDb.OleDbCommand("xxx", objConn) I have put 'xxx' as it doesn't seem to matter what that string is, or am I missing something?
Thanks for your patience!
Jonathan
VB.NET:
Dim objConn As OleDbConnection
Dim objDs As DataSet
Dim ObjDa As OleDbDataAdapter
Dim objRow As DataRow
Try
mstrSQL = "SELECT * FROM ItemsSold WHERE ProductCode = 'T468' AND Colour = 'Blue'"
objDs = New DataSet()
ObjDa = New OleDbDataAdapter(mstrSQL, mstrOLEConnectionString)
ObjDa.Fill(objDs, "xxx")
For Each objRow In objDs.Tables(0).Rows
objConn = New OleDb.OleDbConnection(mstrOLEConnectionString)
objConn.Open()
Dim cmd As New System.Data.OleDb.OleDbCommand("xxx", objConn)
cmd.CommandTimeout = 60
cmd.Connection = objConn
cmd.CommandType = CommandType.Text
cmd.CommandText = "UPDATE ItemsSold SET UnitPrice = '16.50' WHERE RecNo = " & objRow("RecNo")
cmd.ExecuteScalar()
Next
objDs.Dispose()
ObjDa.Dispose()
Exit Sub
Catch f As Exception
'Code here is executed only on any error not caught so far ...
MsgBox(f.Message & vbCrLf & f.StackTrace, MsgBoxStyle.Information, mCompanyName)
End Try