Click here to Skip to main content
15,892,161 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Function getRefundPayId(refundId,parentId)

	If refundId <> "" Then 
	sql = "select PayID from (select PayID,RID from epayment with (nolock) where ParentPayid = " & sqlS(parentId) & " ) As rid Where Rid  = " & sqlS(refundId) 
		set rs = my_conn.execute(sql) 
		if not rs.eof then
			RefundPayid = rs("payid") 
			 
		end if
		set rs=nothing
	End If 
getRefundPayId = RefundPayid 
End Function





//Appreciate someone can convert this to string. Thank you.

What I have tried:

public ActionResult (string refundId, string parentId)
{
sql =
select PayID from (select PayID,RID from epayment with (nolock) where ParentPayid = " & sqlS(parentId) & " ) As rid Where Rid  = " & sqlS(refundId) 
		set rs = my_conn.execute(sql);

{@refundId, refundId},
{@parentId, parentID}

}
Posted
Updated 31-May-20 3:18am

Your request has a few issues:
1. The Classic ASP you provided is a function that is being called by a page.
2. The Classis ASP you provided is calling another custom function: sqlS

So I can only work with what I know, and will be done based on:
1. The .NET equivelant will also be a function, that can be called by the ActionResult method.
2. To protect from SQL Injection the method will use Parameters.
3. sqlS is assumed to be some sort of SQL Sanitatizion
4. The subquery really is not needed.
5. PayID, Rid, and refundID most likely are defined as INT within SQL
6. No need for a "recordset" when only 1 value is being returned.

This will give us something like this
C#
public int getRefundPayId(int refundId, int parentID) {
   int RefundPayid = -1;

   if (refundId != null) {
      string query = "SELECT PayID FROM epayment with (nolock) WHERE ParentPayid = @ParentPayid AND Rid = @Rid";
      using (SqlCommand cmd = new SqlCommand(query, my_conn)) {
         cmd.Parameters.AddWithValue("@ParentPayid", parentId);
         cmd.Parameters.AddWithValue("@Rid", refundId);

         RefundPayid = (int)cmd.ExecuteScalar();
      }
   }
   return RefundPayid;
}
 
Share this answer
 
0) NEVER use string concatenation in SQL queries. You're setting yourself up for SQL injection attacks.

1) You should do all of your SQL worek from a DAL and BLL stack. This separates the backend from the UI.

2) You didn't mention what SQL you're using. Is it MS SQL, MySql, SomeOtherSQL? Because of this, I don't know how to really answer your question.
 
Share this answer
 
Comments
Member 14794855 31-May-20 11:20am    
Hi there,
Thanks for the advise regarding SQL queries. I using MySQL.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900