Split() and Types - VB.Net to C# conversion

I have VB.Net code that builds PL/SQL for a query that returns some data:
Private Function ComposeFileQuery(ByRef cmd As OracleCommand, ByRef ValPairs() As String, _
                                  ByVal SortBy As String, ByVal StartRec As Integer, ByVal EndRec As Integer) As String
  Dim _pair, strQuery As String
  Dim PairNo As Integer = 0
  Dim SortByField, SortByKey As String

  If SortBy.ToUpper.EndsWith(" DESC") Then
     SortByField = SortBy.Substring(0, SortBy.Length - 5)
     SortByKey = " desc "
  ElseIf SortBy.ToUpper.EndsWith(" ASC") Then
     SortByField = SortBy.Substring(0, SortBy.Length - 4)
     SortByKey = " asc "
  Else
     SortByField = SortBy
     SortByKey = " desc "
  End If

  strQuery = _
          "select /*+INDEX(filekeypair filekeypair2)*/ FD_RID, FKP_KEYWORD, FKP_VALUE, FD_FILENAME, FD_LASTMODIFIED from filekeypair,( " + _
          "select distinct p.*, rownum rnum from ( " + _
          "select /*+INDEX(filedirectory filedirattrib_fd_rid)*/ FD_LASTMODIFIED,FD_RID,FD_FILENAME " + _
          "from filedirectory,(select * from filekeypair where FKP_KEYWORD='" + SortByField.ToUpper + "') z where z.FKP_FD_RID(+)=FD_RID "
  For Each _pair In ValPairs
     PairNo += 1
     strQuery += _
         "         and FD_RID in (select /*+INDEX(B FILEKEYPAIR3)*/ b.FKP_FD_RID from filekeypair b " + _
         "                        where upper(b.FKP_KEYWORD) like upper(:Keyword" + PairNo.ToString + ")||'%' " + _
         "                        and upper(b.FKP_VALUE) like upper(:Value" + PairNo.ToString + ")||'%') "
     cmd.Parameters.Add(":Keyword" + CStr(PairNo), OracleType.Char).Value = OraVal(_pair.Split("=")(0))
     cmd.Parameters.Add(":Value" + CStr(PairNo), OracleType.Char).Value = OraVal(_pair.Split("=")(1))
  Next
  strQuery += _
          "order by z.FKP_VALUE " + SortByKey + " ,FD_LASTMODIFIED " + SortByKey + _
          ") p where rownum<=" + EndRec.ToString() + " " + _
          ") where rnum>=" + StartRec.ToString() + " and FKP_FD_RID=FD_RID order by rnum "

  Return strQuery
End Function

Open in new window

And the OraVal function looks like this:
    
Private Function OraVal(ByVal Val As Object) As Object
  If Val.GetType Is GetType(DBNull) Then
     Return " "
  ElseIf Val.GetType Is GetType(Long) Then
     Return Val
  ElseIf Val.GetType Is GetType(Integer) Then
     Return Val
  ElseIf Val = "" Then
     Return " "
  Else
     Return Val
  End If
End Function

Open in new window

Now, I'm trying to convert this to C# and this is what I get from the online coverters:
private string ComposeFileQuery(ref OracleCommand cmd, ref string[] ValPairs, string SortBy, int StartRec, int EndRec)
{
	string _pair = null;
	string strQuery = null;
	int PairNo = 0;
	string SortByField = null;
	string SortByKey = null;

	if (SortBy.ToUpper().EndsWith(" DESC")) {
		SortByField = SortBy.Substring(0, SortBy.Length - 5);
		SortByKey = " desc ";
	} else if (SortBy.ToUpper().EndsWith(" ASC")) {
		SortByField = SortBy.Substring(0, SortBy.Length - 4);
		SortByKey = " asc ";
	} else {
		SortByField = SortBy;
		SortByKey = " desc ";
	}

	strQuery = "select /*+INDEX(filekeypair filekeypair2)*/ FD_RID, FKP_KEYWORD, FKP_VALUE, FD_FILENAME, FD_LASTMODIFIED from filekeypair,( " + "select distinct p.*, rownum rnum from ( " + "select /*+INDEX(filedirectory filedirattrib_fd_rid)*/ FD_LASTMODIFIED,FD_RID,FD_FILENAME " + "from filedirectory,(select * from filekeypair where FKP_KEYWORD='" + SortByField.ToUpper() + "') z where z.FKP_FD_RID(+)=FD_RID ";
	foreach (string _pair_loopVariable in ValPairs) {
		_pair = _pair_loopVariable;
		PairNo += 1;
		strQuery += "         and FD_RID in (select /*+INDEX(B FILEKEYPAIR3)*/ b.FKP_FD_RID from filekeypair b " + "                        where upper(b.FKP_KEYWORD) like upper(:Keyword" + PairNo.ToString() + ")||'%' " + "                        and upper(b.FKP_VALUE) like upper(:Value" + PairNo.ToString() + ")||'%') ";
		cmd.Parameters.Add(":Keyword" + Convert.ToString(PairNo), OracleType.Char).Value = OraVal(_pair.Split("=")[0]);
		cmd.Parameters.Add(":Value" + Convert.ToString(PairNo), OracleType.Char).Value = OraVal(_pair.Split("=")[1]);
	}
	strQuery += "order by z.FKP_VALUE " + SortByKey + " ,FD_LASTMODIFIED " + SortByKey + ") p where rownum<=" + EndRec.ToString() + " " + ") where rnum>=" + StartRec.ToString() + " and FKP_FD_RID=FD_RID order by rnum ";

	return strQuery;
}


private object OraVal(object Val)
{
	if (object.ReferenceEquals(Val.GetType, typeof(DBNull))) {
		return " ";
	} else if (object.ReferenceEquals(Val.GetType, typeof(long))) {
		return Val;
	} else if (object.ReferenceEquals(Val.GetType, typeof(int))) {
		return Val;
	} else if (string.IsNullOrEmpty(Val)) {
		return " ";
	} else {
		return Val;
	}
}

Open in new window

I have modified the OraVal function to this:
private object OraVal(object Val)
{
    switch (Type.GetTypeCode(Val.GetType()))
    {
        case TypeCode.DBNull:
            return " ";
        case TypeCode.Int64:
            return Val;
        case TypeCode.Int32:
            return Val;
        case TypeCode.Empty:
            return " ";
        default:
            return Val;
    }
}

Open in new window

What I'm having problems with is this code:
cmd.Parameters.Add(":Keyword" + Convert.ToString(PairNo), OracleType.Char).Value = OraVal(_pair.Split("=")[0]);
cmd.Parameters.Add(":Value" + Convert.ToString(PairNo), OracleType.Char).Value = OraVal(_pair.Split("=")[1]);

Open in new window

Can anyone help me out on this one? Personally, I don't think I really need to do the OraVal() thing anyway...
LVL 26
Eddie ShipmanAll-around developerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

SimonPrice3376Commented:
You need to change this bit  
_pair.Split("=")

Open in new window

in C# you need to change your double quotes \ speech marks for single quotes like this
_pair.Split('=')
 

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Eddie ShipmanAll-around developerAuthor Commented:
How stupid of me...
0
SimonPrice3376Commented:
Its not stupid at all, there are many subtle differences in VB and C#, I started off in VB and now work in C# and had many issues similar to this.
0
Eddie ShipmanAll-around developerAuthor Commented:
Oh, it's not that I'm a noob at C#, I just forgot. I've been doing both for several years and sorry I missed that. I'm hoping that the rest of the conversion works ;-)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.