Home | Forums | Contact | Search | Syndication  
 
 [login] [create account]   Sunday, August 17, 2025 
 
slxdeveloper.com Community Forums  
   
The Forums on slxdeveloper.com are now retired. The forum archive will remain available for the time being. Thank you for your participation on slxdeveloper.com!
 Web Forums - SalesLogix Web Platform & Application Architect
Forum to discuss the use of the SalesLogix Web Platform, Client and Customer Portals, and the Application Architect (For version 7.2 and higher only). View the code of conduct for posting guidelines.
Forums RSS Feed


 Back to Forum List | Back to SalesLogix Web Platform & Application Architect | New ThreadView:  Search:  
 Author  Thread: C# Snippet to run SQL Update
Andrew Sokolsky
Posts: 26
 
C# Snippet to run SQL UpdateYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 30 Jan 09 11:45 AM
I am new to the C# Snippet world here. I need to write a C# Snippet that executes a SQL update command after a new record is inserted (by Quickform). Does anyone have the entire code (example) that they have used to do this?
[Reply][Quote]
Ryan Farley
Posts: 2265
slxdeveloper.com Site Administrator
Top 10 forum poster: 2265 posts
 
Re: C# Snippet to run SQL UpdateYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 30 Jan 09 10:30 PM
Default response to "need to execute a SQL update statement" in SLX web is "you're going about it wrong"

What exactly are you trying to do in the snippet? We can help you to do it the right way. If what you really need to do is run a SQL statement then we can help with that too, but chances are there is a better way to accomplish what you're after.
[Reply][Quote]
Andrew Sokolsky
Posts: 26
 
Re: C# Snippet to run SQL UpdateYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 02 Feb 09 2:28 PM
Ok. Basically I am trying to get the UserID of a UserName Lookup (from the UserInfo table) to update a UserID field (in a new custom table) on the record just inserted via a quickform. I have tried creating a relationship from the UserInfo table to my new custom table but this does not work.
[Reply][Quote]
Ryan Farley
Posts: 2265
slxdeveloper.com Site Administrator
Top 10 forum poster: 2265 posts
 
Re: C# Snippet to run SQL UpdateYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 02 Feb 09 2:38 PM
Not sure I understand completely. Are you saying you have a User lookup on the form and want to store the selected user, right? Create your relationship to the User entity, instead of UserInfo. Then you can just bind the User lookup to the relationship property.

Is that what you are after?
[Reply][Quote]
Andrew Sokolsky
Posts: 26
 
Re: C# Snippet to run SQL UpdateYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 02 Feb 09 2:45 PM
I want to store the selected UserName and User ID to my custom table.
[Reply][Quote]
Ryan Farley
Posts: 2265
slxdeveloper.com Site Administrator
Top 10 forum poster: 2265 posts
 
Re: C# Snippet to run SQL UpdateYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 02 Feb 09 2:53 PM
Quote:
Originally posted by Andrew Sokolsky

I want to store the selected UserName and User ID to my custom table.


By simply binding the control should accomplish what you're after. Otherwise, the User lookup control will return a User object. You could easily do something like this on the Change action of the User lookup:

Sage.Entity.Interfaces.IMyEntity myentity = this.BindingSource.Current as Sage.Entity.Interfaces.IMyEntity;

Sage.Entity.Interfaces.IUser user = lookupUser.LookupResultValue as Sage.Entity.Interfaces.IUser;
myentity.SomeUserId = user.Id.ToString();
myentity.SomeUserName = user.UserInfo.Username;


Does that make sense?

-Ryan
[Reply][Quote]
Andrew Sokolsky
Posts: 26
 
Re: C# Snippet to run SQL UpdateYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 02 Feb 09 2:56 PM
I'll try that. Thanks!
[Reply][Quote]
Andrew Sokolsky
Posts: 26
 
Re: C# Snippet to run SQL UpdateYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 02 Feb 09 5:22 PM
Ok. A beginner here with the C# Snippet. 1) Do I use C# Snippet Action Item or C# Snippet. 2) Do I use the default "Usings" for the regions. 3) For "myentity" should I replace this with the custom entity I created in every instance in the code. 4) For "SomeUserID" and "SomeUserName", should these be replaced with their real field names in my entity?

Thanks
[Reply][Quote]
Andrew Sokolsky
Posts: 26
 
Re: C# Snippet to run SQL UpdateYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 03 Feb 09 6:49 PM
Ryan,

I tried to get your code above to work, but no luck. I put this C# Snippet together but it wont' work. Any part of the code that needs remediation.

Thanks

__________________________________________________________

#region Usings
using System;
using Sage.Entity.Interfaces;
using Sage.Form.Interfaces;
using Sage.Platform.Repository;
using Sage.Platform;
#endregion Usings

namespace Sage.BusinessRules.CodeSnippets
{
public static partial class AccountBusinessRules
{
public static void GetAccountRolesCurrentUserStep1( IAccount account, out object result)
{

//Get your Conn String..

Sage.Platform.Data.IDataService service = Sage.Platform.Application.ApplicationContext.Current.Services.Get();
string constr = service.GetConnectionString();
//Declare your command, and connection pieces..
System.Data.OleDb.OleDbCommand comm;
System.Data.OleDb.OleDbConnection conn;

conn = new System.Data.OleDb.OleDbConnection(constr);
conn.Open();

string sql = "UPDATE ACCOUNTROLES";
"SET USERID = USERINFO.USERID";
"FROM ACCOUNTROLES INNER JOIN";
"USERINFO ON ACCOUNTROLES.ACCOUNT_NAM = USERINFO.USERNAME";

comm = new System.Data.OleDb.OleDbCommand(sql, conn);
comm.ExecuteNonQuery();


//Cleanup..
comm.Dispose();
conn.Dispose();



}
}
}

[Reply][Quote]
 Page 1 of 1 
  You can subscribe to receive a daily forum digest in your user profile. View the site code of conduct for posting guidelines.

   Forum RSS Feed - Subscribe to the forum RSS feed to keep on top of the latest forum activity!
 

 
 slxdeveloper.com is brought to you courtesy of Ryan Farley & Customer FX Corporation.
 This site, and all contents herein, are Copyright © 2025 Customer FX Corporation. The information and opinions expressed here are not endorsed by Sage Software.

code of conduct | Subscribe to the slxdeveloper.com Latest Article RSS feed
   
 
page cache (param): 8/17/2025 3:15:13 PM