Results 1 to 4 of 4

Thread: SQL / C# Question! *Resolved*

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Sep 2002
    Posts
    100

    SQL / C# Question! *Resolved*

    Hello,

    This is a snippet from my code, I do this several times! I was just wondering if anyone had a suggestion for a simpler way to do the following:


    Code:
         case "address_map":
    		RS = DB.Execute(myData.pService.SQL_ADDRESS_MAP_CHECK.Replace("%1", A[1]), out ob, -1);
    		if (!RS.EOF)
    		{
    			Out_Data += "error ";
    		}
    		else
    		{
    			DB.Execute("insert into address_maps (Mail_Box_ID, Email, Status, Misc) Values('" + A[2] + "','" + A[3] + "','" + A[4] + "','" + A[5] + "')", out ob, -1);
    			Out_Data += "good ";
    		}
    		Send(Out_Data + Environment.NewLine);
    		break;
    
    	case "domain":
    		RS = DB.Execute("select domains.Domain_ID, domains.Domain, domains.Post_Office_ID, domains.Status, domains.Misc from domains where domains.Domain = '" + A[2] + "'", out ob, -1);
    		if (!RS.EOF)
    		{
    			Out_Data += "error ";
    		}
    		else
    		{
    			DB.Execute(myData.pService.SQL_DOMAIN_CHECK.Replace("%1", A[2]).Replace("%2", A[3]).Replace("%3", A[4]).Replace("%4", A[5]), out ob, -1);
    			Out_Data += "good ";
    		}
    		Send(Out_Data + Environment.NewLine);
    		break;
    Thank YOU!!!
    Mitchel
    Last edited by toto; Jun 11th, 2003 at 06:49 PM.

  2. #2
    Lively Member
    Join Date
    Jun 2003
    Posts
    83
    Code:
    switch (Whatever) {
    	case "address_map":
    		RS = DB.Execute(myData.pService.SQL_ADDRESS_MAP_CHECK.Replace("%1", A[1]), out ob, -1);
    		break;
    	case "domain":
    		RS = DB.Execute("select domains.Domain_ID, domains.Domain, domains.Post_Office_ID, domains.Status, domains.Misc from domains where domains.Domain = '" + A[2] + "'", out ob, -1);
    		break;
    }
    if (!RS.EOF) {
    	Out_Data += "error ";
    } else {
    	switch (Whatever) {
    		case "address_map":
    			DB.Execute("insert into address_maps (Mail_Box_ID, Email, Status, Misc) Values('" + A[2] + "','" + A[3] + "','" + A[4] + "','" + A[5] + "')", out ob, -1);
    			break;
    		case "domain":
    			DB.Execute(myData.pService.SQL_DOMAIN_CHECK.Replace("%1", A[2]).Replace("%2", A[3]).Replace("%3", A[4]).Replace("%4", A[5]), out ob, -1);
    			break;
    	}
    	Out_Data += "good ";
    	Send(Out_Data + Environment.NewLine);
    }
    Last edited by transio; Jun 11th, 2003 at 05:22 PM.
    - Steve

    "I'm glad I wore these pants."

  3. #3
    Lively Member
    Join Date
    Jun 2003
    Posts
    83
    Better yet, try something like this:
    Code:
    switch (Whatever) {
    	case "address_map":
    		selectCmd = myData.pService.SQL_ADDRESS_MAP_CHECK.Replace("%1", A[1]);
    		insertCmd = "insert into address_maps (Mail_Box_ID, Email, Status, Misc) Values('" + A[2] + "','" + A[3] + "','" + A[4] + "','" + A[5] + "')";
    		break;
    	case "domain":
    		selectCmd = "select domains.Domain_ID, domains.Domain, domains.Post_Office_ID, domains.Status, domains.Misc from domains where domains.Domain = '" + A[2] + "'";
    		insertCmd = myData.pService.SQL_DOMAIN_CHECK.Replace("%1", A[2]).Replace("%2", A[3]).Replace("%3", A[4]).Replace("%4", A[5]);
    		break;
    }
    
    RS = DB.Execute(selectCmd, out ob, -1);
    if (!RS.EOF) {
    	Out_Data += "error ";
    } else {
    	DB.Execute(selectCmd, out ob, -1);
    	Out_Data += "good ";
    }
    Send(Out_Data + Environment.NewLine);
    - Steve

    "I'm glad I wore these pants."

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Sep 2002
    Posts
    100
    Very cool, I like the second method, both are better though then mine. Thanks transio.

    Thanks a lot,
    Mitchel

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width