0

I know this is very basic, but I can't seem to get it right. I have this datatable that I will fill with processed information from my database.

After searching if the EmpRequestID has already been added in the Datatable, I want to be able to get the value of the column named "RequestedEmp" of the returned row and check if already contains the initials that my variable is currently hosting (it is in a loop). If it does not, append the initials in the variable in the existing initials in the row.

DataRow[] MyEmpReq_Row = MyEmpRequests_DataTable.Select("EmpRequestID='" + EmpRequestID + "'");
int SameReqID = MyEmpReq_Row.Length;

if (MyEmpReq_Row > 0) //REQ ID IN DT, MULTIPLE EMP 1 REQUEST
{
    //INSERT HERE 
}
else //ID NOT IN DT YET
{
    MyEmpRequests_DataTable.Rows.Add(EmpRequestID, ActionBy, Requested_Initials, DateSubmitted, RequestStatus);
}

I want to be able to do something like this

string RetrievedInitials = MyEmpReq_Row["RequestedEmp"].ToString();

if (RetrievedInitials LIKE '%" + Requested_Initials + "'") // but if statements doesnt have LIKE

or this and then know if the column contains the value or not.

MyEmpReq_Row.Select("RequestedEmp LIKE '%" + Requested_Initials + "'");
3
  • Have you looked at the Contains() method Commented Jan 23, 2012 at 14:43
  • @DJKRAZE No I havent, I'll google it. Commented Jan 23, 2012 at 14:47
  • The Answer is provided below from @msmucker0527 Commented Jan 23, 2012 at 14:49

2 Answers 2

1
if (RetrievedInitials.Contains(Requested_Initials))
Sign up to request clarification or add additional context in comments.

1 Comment

Ritzel glad that msMcuker and myself were able to lead you in the right direction..
0

Take a look at the string class: http://msdn.microsoft.com/en-us/library/system.string.aspx

As already mentioned by some other posters, the Contains() method may be of use. However, you should also look at EndsWith() (which is more in line with your use of the wildcard in your LIKE query) and StartsWith().

Example:

if (RetrievedInitials.EndsWith(Requested_Initials))

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.