0

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

1
  • dude hard coded values? and your SQL statements should be parametrized. That's some nice SQL injection risks there. Commented Oct 1, 2012 at 21:15

3 Answers 3

1

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") 
Sign up to request clarification or add additional context in comments.

2 Comments

Your c# needs to be == not =
@Scott - You could edit it yourself... If you see an obvious mistake - correct it. It's the Stack Overflow way.
0

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

}

Comments

0

You can merge all like

(if var1 == x && var2 == y && var3 == z) {
    //Do what you want
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.