﻿<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>StrataFrame Forum » StrataFrame Application Framework - V1 » Business Objects and Data Access (How do I?)  » Using insert stored procedures</title><generator>InstantForum 2017-1 Final</generator><description>StrataFrame Forum</description><link>http://forum.strataframe.net/</link><webMaster>StrataFrame Forum</webMaster><lastBuildDate>Tue, 09 Jun 2026 13:24:19 GMT</lastBuildDate><ttl>20</ttl><item><title>Using insert stored procedures</title><link>http://forum.strataframe.net/FindPost543.aspx</link><description>Can anyone give me a sample of saving data with a stored procedure. I am trying to return the uniqueidentifier and I'm not sure exactly how to go about this.&lt;/P&gt;&lt;P&gt;Thanks in advance.</description><pubDate>Thu, 23 Feb 2006 10:25:45 GMT</pubDate><dc:creator>Randy Smith</dc:creator></item><item><title>RE: Using insert stored procedures</title><link>http://forum.strataframe.net/FindPost568.aspx</link><description>Great!! Thanks for all your help.</description><pubDate>Thu, 23 Feb 2006 10:25:45 GMT</pubDate><dc:creator>Randy Smith</dc:creator></item><item><title>RE: Using insert stored procedures</title><link>http://forum.strataframe.net/FindPost567.aspx</link><description>Yes, it is possible to use a GUID as a primary key... I would recommend that you set the pk value within your SetDefaultValues event handler within the business object.  Then, you can turn off the use of the stored procedures, and set the PrimaryKeyIsAutoIncremented property to False.  However, if you want the server to assign the value, you'll need to set the "Default Value" of your field within the database to "(NEWID())", and leave the PrimaryKeyIsAutoIncremented = True so that the value will be retrieved.&lt;br&gt;
&lt;br&gt;
If you want to assign the PK on the client side, the code would look like this:&lt;br&gt;
&lt;br&gt;
VB:&lt;br&gt;
Private Sub MyBO_SetDefaultValues()&lt;br&gt;
     '-- Set the pk value&lt;br&gt;
     Me.pkfield = Guid.NewGuid() '-- Creates a new, random GUID just like the NEWID() SQL method&lt;br&gt;
End Sub&lt;br&gt;
&lt;br&gt;
C#:&lt;br&gt;
private void MyBO_SetDefaultValues()&lt;br&gt;
{&lt;br&gt;
	//-- Set the pk value&lt;br&gt;
	this.pkfield = Guid.NewGuid(); //-- Creates a new, random GUID just like the NEWID() SQL method&lt;br&gt;
}</description><pubDate>Thu, 23 Feb 2006 08:52:25 GMT</pubDate><dc:creator>StrataFrame Team</dc:creator></item><item><title>RE: Using insert stored procedures</title><link>http://forum.strataframe.net/FindPost566.aspx</link><description>Thanks for the information Ben. That fixed my problem. Is it possible to use the uniqueidentifier field without using the stored procedure ?</description><pubDate>Tue, 21 Feb 2006 15:38:59 GMT</pubDate><dc:creator>Randy Smith</dc:creator></item><item><title>RE: Using insert stored procedures</title><link>http://forum.strataframe.net/FindPost565.aspx</link><description>I see in your database table that the field receiving the @Admin value is actually [Administrator].  You have to name the stored procedure parameters with the same name as the field within the business object (plus the StoredProcedureParameterPrefix property value).  So, if you're StoredProcedureParameterPrefix property equals "@p_", then, you'll need to name you're parameters within your stored procedure each "@p_FieldName" ("@p_Administrator" in this case, not "@p_Admin"), so, since the default value for the prefix is just "@", you'll need to change that "@Admin" parameter to "@Administrator" because the data layer is expecting you to use the same name as the field within the business object.  If you run into a name that's a reserved name on SQL Server, then just change the default StoredProcedureParameterPrefix value.</description><pubDate>Tue, 21 Feb 2006 14:34:25 GMT</pubDate><dc:creator>StrataFrame Team</dc:creator></item><item><title>RE: Using insert stored procedures</title><link>http://forum.strataframe.net/FindPost553.aspx</link><description>Ben,&lt;P&gt;I still must be doing something wrong. I am now getting the following error when trying to run the stored procedure from the BO.&lt;/P&gt;&lt;P&gt;BusinessLayerException&lt;BR&gt;&amp;nbsp;An error occurred while saving an the data to the server.&lt;BR&gt;DataLayerSavingException&lt;BR&gt;&amp;nbsp;Procedure or Function 'sp_User_Insert' expects parameter &lt;A href="mailto:'@Admin'"&gt;'@Admin'&lt;/A&gt;, which was not supplied.&lt;BR&gt;SqlException&lt;BR&gt;&amp;nbsp;Procedure or Function 'sp_User_Insert' expects parameter &lt;A href="mailto:'@Admin'"&gt;'@Admin'&lt;/A&gt;, which was not supplied.&lt;/P&gt;&lt;P&gt;Source&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : MicroFour StrataFrame Business&lt;/P&gt;&lt;P&gt;Stack Trace: &lt;BR&gt;&amp;nbsp;&amp;nbsp; at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)&lt;BR&gt;&amp;nbsp;&amp;nbsp; at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)&lt;BR&gt;&amp;nbsp;&amp;nbsp; at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)&lt;BR&gt;&amp;nbsp;&amp;nbsp; at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)&lt;BR&gt;&amp;nbsp;&amp;nbsp; at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)&lt;BR&gt;&amp;nbsp;&amp;nbsp; at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async)&lt;BR&gt;&amp;nbsp;&amp;nbsp; at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result)&lt;BR&gt;&amp;nbsp;&amp;nbsp; at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult result, String methodName, Boolean sendToPipe)&lt;BR&gt;&amp;nbsp;&amp;nbsp; at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()&lt;BR&gt;&amp;nbsp;&amp;nbsp; at MicroFour.StrataFrame.Data.SqlDataSourceItem.UpdateRow(QueryInformation QueryInfo, DataRow RowToUpdate, ConcurrencyExceptionHandler ConcurrencyHandler)&lt;BR&gt;&amp;nbsp;&amp;nbsp; at MicroFour.StrataFrame.Data.DataLayer.UpdateDataTableThread(Object ThreadParams)&lt;BR&gt;&amp;nbsp;&amp;nbsp; at MicroFour.StrataFrame.Data.DataLayer.SaveByForm(DataTable TableToSave, Boolean Transactional, String TransactionKey)&lt;BR&gt;&amp;nbsp;&amp;nbsp; at MicroFour.StrataFrame.Business.BusinessLayer.SaveByForm(Boolean Transactional, String TransactionKey)&lt;BR&gt;&amp;nbsp;&amp;nbsp; at MicroFour.StrataFrame.UI.Windows.Forms.BaseForm.Save(Boolean Transactional, String TransactionKey)&lt;BR&gt;&amp;nbsp;&amp;nbsp; at MicroFour.StrataFrame.UI.Windows.Forms.BaseForm.Save()&lt;BR&gt;&amp;nbsp;&amp;nbsp; at MicroFour.StrataFrame.UI.Windows.Forms.MaintenanceFormToolStrip.cmdSave_Click(Object sender, EventArgs e)&lt;BR&gt;&amp;nbsp;&amp;nbsp; at System.Windows.Forms.ToolStripItem.RaiseEvent(Object key, EventArgs e)&lt;BR&gt;&amp;nbsp;&amp;nbsp; at System.Windows.Forms.ToolStripButton.OnClick(EventArgs e)&lt;BR&gt;&amp;nbsp;&amp;nbsp; at System.Windows.Forms.ToolStripItem.HandleClick(EventArgs e)&lt;BR&gt;&amp;nbsp;&amp;nbsp; at System.Windows.Forms.ToolStripItem.HandleMouseUp(MouseEventArgs e)&lt;BR&gt;&amp;nbsp;&amp;nbsp; at System.Windows.Forms.ToolStripItem.FireEventInteractive(EventArgs e, ToolStripItemEventType met)&lt;BR&gt;&amp;nbsp;&amp;nbsp; at System.Windows.Forms.ToolStripItem.FireEvent(EventArgs e, ToolStripItemEventType met)&lt;BR&gt;&amp;nbsp;&amp;nbsp; at System.Windows.Forms.ToolStrip.OnMouseUp(MouseEventArgs mea)&lt;BR&gt;&amp;nbsp;&amp;nbsp; at System.Windows.Forms.Control.WmMouseUp(Message&amp;amp; m, MouseButtons button, Int32 clicks)&lt;BR&gt;&amp;nbsp;&amp;nbsp; at System.Windows.Forms.Control.WndProc(Message&amp;amp; m)&lt;BR&gt;&amp;nbsp;&amp;nbsp; at System.Windows.Forms.ScrollableControl.WndProc(Message&amp;amp; m)&lt;BR&gt;&amp;nbsp;&amp;nbsp; at System.Windows.Forms.ToolStrip.WndProc(Message&amp;amp; m)&lt;BR&gt;&amp;nbsp;&amp;nbsp; at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message&amp;amp; m)&lt;BR&gt;&amp;nbsp;&amp;nbsp; at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message&amp;amp; m)&lt;BR&gt;&amp;nbsp;&amp;nbsp; at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)&lt;/P&gt;&lt;P&gt;Here is the stored procedure:&lt;/P&gt;&lt;FONT color=#0000ff size=2&gt;&lt;P&gt;set&lt;/FONT&gt;&lt;FONT color=#000000 size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;ANSI_NULLS&lt;/FONT&gt;&lt;FONT color=#000000 size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;ON&lt;/P&gt;&lt;P&gt;set&lt;/FONT&gt;&lt;FONT color=#000000 size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;QUOTED_IDENTIFIER&lt;/FONT&gt;&lt;FONT color=#000000 size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;ON&lt;/P&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;P&gt;go&lt;/P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;P&gt;ALTER&lt;/FONT&gt;&lt;FONT color=#000000 size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;procedure&lt;/FONT&gt;&lt;FONT color=#000000 size=2&gt; [dbo]&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;.&lt;/FONT&gt;&lt;FONT color=#000000 size=2&gt;[sp_User_Insert] &lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;(&lt;/FONT&gt;&lt;FONT size=2&gt;@UserID &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;UniqueIdentifier&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;OUTPUT&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;,&lt;/FONT&gt;&lt;FONT size=2&gt;@UserName [NVarchar] &lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;(&lt;/FONT&gt;&lt;FONT size=2&gt;50&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;),&lt;/FONT&gt;&lt;FONT size=2&gt;@Password [NVarchar] &lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;(&lt;/FONT&gt;&lt;FONT size=2&gt;50&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;),&lt;/FONT&gt;&lt;FONT size=2&gt;@Initials [NVarchar] &lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;(&lt;/FONT&gt;&lt;FONT size=2&gt;3&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;),&lt;/FONT&gt;&lt;FONT size=2&gt;@Email [NVarchar] &lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;(&lt;/FONT&gt;&lt;FONT size=2&gt;50&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;),&lt;/FONT&gt;&lt;FONT size=2&gt;@Admin [Bit]&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;,&lt;/FONT&gt;&lt;FONT size=2&gt;@Created [DateTime]&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;,&lt;/FONT&gt;&lt;FONT size=2&gt;@LastUpd [DateTime]&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;)&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color=#0000ff size=2&gt;AS&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;FONT color=#000000&gt; &lt;/FONT&gt;&lt;/P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;P&gt;BEGIN&lt;/P&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;Select&lt;/FONT&gt;&lt;FONT size=2&gt; @UserID &lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;=&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#ff00ff size=2&gt;NEWID&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;();&lt;/P&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;Insert&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;into&lt;/FONT&gt;&lt;FONT size=2&gt; [dbo]&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;.&lt;/FONT&gt;&lt;FONT size=2&gt;[Users] &lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;(&lt;/FONT&gt;&lt;FONT size=2&gt;[UserID]&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;,&lt;/FONT&gt;&lt;FONT size=2&gt;[UserName]&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;,&lt;/FONT&gt;&lt;FONT size=2&gt;[Password]&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;,&lt;/FONT&gt;&lt;FONT size=2&gt;[Initials]&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;,&lt;/FONT&gt;&lt;FONT size=2&gt;[Email]&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;,&lt;/FONT&gt;&lt;FONT size=2&gt;[Administrator]&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;,&lt;/FONT&gt;&lt;FONT size=2&gt;[Created]&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;,&lt;/FONT&gt;&lt;FONT size=2&gt;[LastUpd]&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;)&lt;/P&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;Values&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;(&lt;/FONT&gt;&lt;FONT size=2&gt;@UserID&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;,&lt;/FONT&gt;&lt;FONT size=2&gt;@UserName&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;,&lt;/FONT&gt;&lt;FONT size=2&gt;@Password&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;,&lt;/FONT&gt;&lt;FONT size=2&gt;@Initials&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;,&lt;/FONT&gt;&lt;FONT size=2&gt;@Email&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;,&lt;/FONT&gt;&lt;FONT size=2&gt;@Admin&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;,&lt;/FONT&gt;&lt;FONT size=2&gt;@Created&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;,&lt;/FONT&gt;&lt;FONT size=2&gt;@LastUpd&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;);&lt;/P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;P&gt;end&lt;/P&gt;&lt;P&gt;&lt;FONT color=#111111&gt;My business object is populating the Created and Lastupd field from the set default values. I have a form that has the username,password,initials,email and a checkbox for the admin field. I can't figure out what is wrong. I ran the stored proc inside SQL management console and it works just fine.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color=#111111&gt;Thanks for your help.&lt;/FONT&gt;&lt;/FONT&gt;</description><pubDate>Fri, 17 Feb 2006 14:07:08 GMT</pubDate><dc:creator>Randy Smith</dc:creator></item><item><title>RE: Using insert stored procedures</title><link>http://forum.strataframe.net/FindPost548.aspx</link><description>Also, make sure that you're PrimaryKeyIsAutoIncremented property is set to True so that the business object's data layer knows that it should retrieve the assigned GUID from the server after the INSERT.</description><pubDate>Thu, 16 Feb 2006 10:10:34 GMT</pubDate><dc:creator>StrataFrame Team</dc:creator></item><item><title>RE: Using insert stored procedures</title><link>http://forum.strataframe.net/FindPost547.aspx</link><description>So, your server assigns the new GUID for the new record?  And the primary key is a GUID?&lt;br&gt;
&lt;br&gt;
Then you'll want your stored procedure to look like this:&lt;br&gt;
&lt;br&gt;
CREATE Procedure sp_MyTable_Insert ( @field_pk GUID OUTPUT, @field_1 INT, @field_2 INT)&lt;br&gt;
AS&lt;br&gt;
BEGIN &lt;br&gt;
SELECT @field_pk = NEWID();&lt;br&gt;
INSERT INTO MyTable (field_pk, field_1, field_2)&lt;br&gt;
VALUES (@field_pk, @field_1, @field_2);&lt;br&gt;
END	&lt;br&gt;
GO&lt;br&gt;
&lt;br&gt;
Don't forget to define the GUID as a OUTPUT.  Then get the guid and insert it into the row as the pk, and it will be returned and retrieved into the business object by the output variable.</description><pubDate>Thu, 16 Feb 2006 10:07:47 GMT</pubDate><dc:creator>StrataFrame Team</dc:creator></item></channel></rss>