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!
|
|
C# Snippet to run SQL Update
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? |
|
|
|
Re: C# Snippet to run SQL Update
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. |
|
|
|
Re: C# Snippet to run SQL Update
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. |
|
|
|
Re: C# Snippet to run SQL Update
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? |
|
|
| |
|
Re: C# Snippet to run SQL Update
Posted: 02 Feb 09 2:53 PM
|
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 |
|
|
| |
|
Re: C# Snippet to run SQL Update
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 |
|
|
|
Re: C# Snippet to run SQL Update
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();
} } }
|
|
|
|