Reputation: 1
Im having a problem with an IF statement.
The purpose of this statement is that all 3 managers must approve an order before it can prossesed.
This is the statement :
Dim RstAllchk
Dim RstAllchk_numRows
Set RstAllchk = Server.CreateObject("ADODB.Recordset")
RstAllchk.ActiveConnection = MM_DBConn_STRING
RstAllchk.Source = "SELECT comitee.OrderNo, comitee.Bart, comitee.Carel, comitee.Charl FROM comitee WHERE (((comitee.OrderNo)='" + Replace(RstAllData__varOrderNum, "'", "''") + "'));"
RstAllchk.CursorType = 0
RstAllchk.CursorLocation = 2
RstAllchk.LockType = 1
RstAllchk.Open()
RstAllchk_numRows = 0
if (RstAllchk.Fields.Item("Bart").Value)= "Approved" then
if (RstAllchk.Fields.Item("Carel").Value)= "Approved" then
if (RstAllchk.Fields.Item("Charl").Value)= "Approved" then
set cdata1 = Server.CreateObject("ADODB.Command")
cdata1.ActiveConnection = MM_DBConn_STRING
cdata1.CommandText = " UPDATE TblOrderData SET Fldapproved = 'Approved' WHERE FldOrderID = '" & RstAllData__varOrderNum & "'"
cdata1.CommandType = 1
cdata1.CommandTimeout = 0
cdata1.Prepared = true
cdata1.Execute()
cdata1.ActiveConnection.Close
set cdata2 = Server.CreateObject("ADODB.Command")
cdata2.ActiveConnection = MM_DBConn_STRING
cdata2.CommandText = " UPDATE TblOrderDetail SET FldMainapproved = 'Approved' WHERE FldOrderNum = '" & RstAllData__varOrderNum & "'"
cdata2.CommandType = 1
cdata2.CommandTimeout = 0
cdata2.Prepared = true
cdata2.Execute()
cdata2.ActiveConnection.Close
`
Sometimes if only one of the managers confirmed the order, the order is still approved. I have been struggling with this for days. Hope any of you can give me some advice.
Thanks
Upvotes: 0
Views: 289
Reputation: 499382
Assuming VB.NET:
IF (RstAllchk.Fields.Item("Bart").Value = "Approved" AND _
RstAllchk.Fields.Item("Carel").Value = "Approved" AND _
RstAllchk.Fields.Item("Charl").Value = "Approved") THEN
In C#:
if (RstAllchk.Fields.Item("Bart").Value == "Approved" &&
RstAllchk.Fields.Item("Carel").Value == "Approved" &&
RstAllchk.Fields.Item("Charl").Value == "Approved")
Upvotes: 1
Reputation: 1433
You can merge all like
(if var1 == x && var2 == y && var3 == z) {
//Do what you want
}
Upvotes: 0
Reputation: 29000
With C# (&& is And , == is equal)
if ( RstAllchk.Fields.Item("Bart").Value == "Approved"
&& RstAllchk.Fields.Item("Carel").Value == "Approved"
&& RstAllchk.Fields.Item("Charl").Value == "Approved"
)
{
//treatment
}
Upvotes: 0