Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Saving using Stored Proc with Output Parameters
Message
De
03/12/2004 10:15:54
Dan Greenberg
Freedom of Information, Inc.
Parker, Colorado, États-Unis
 
 
À
Tous
Information générale
Forum:
ASP.NET
Catégorie:
The Mere Mortals .NET Framework
Titre:
Saving using Stored Proc with Output Parameters
Versions des environnements
Environment:
C# 1.1
OS:
Windows XP SP1
Network:
Windows 2003 Server
Database:
MS SQL Server
Divers
Thread ID:
00966712
Message ID:
00966712
Vues:
61
Hi everyone,

I am very new to MM.Net. I am trying to save an updated record from a Windows form that is based on mmBusinessform. I need to be able to do it with stored procedures. In the case of an Update, I have been getting back a timestamp which in my raw .Net setup is being replaced in the correct places in the DataSet. Then if the record is resaved, the SP checks that the new timestamp and the one in the SQL Server table are the same as a condition of updating. If the timestamp in the table has been changed since the last save, then a concurrency error is thrown.

---------------------------------------------------------------------------
When attempting to save an updated record using a Stored Proc that has the
timestamp Output Parameter I get the following error:

---------------------------------------------------------------------------
Invalid object name 'Message'.
---------------------------------------------------------------------------

First off the data will save just fine if I do not include an output
parameter. There is no possibility of a real concurrency error since I am
the only one trying to update the table - which is only in my Development
System.

I am using the standard mm Save button which I just dropped on the form.

I created a custom data adapter and the correct overrides as instructed in the
help topic "Creating Custom Data Access Classes"

The SP works individually when called from the Query Analyzer. The Select
populates the form. Not really sure where to go from here -
have spent a bunch of time trying to debug

---------------------------------------------------------------------------
Here is the relevant code from the busUserPrefs constructor - based on
ABusinessObject which is a vanilla mmBusinessObject. The constructor of
ABusinessObject contains just the DatabaseKey property since it is the same
for the whole application.
---------------------------------------------------------------------------

public busUserPrefs()
{
this.TableName = "UserPrefs";
this.PrimaryKey = "iuserpref";

---------------------------------------------------------------------------
Here is the override in the Business Object Class
---------------------------------------------------------------------------
protected override mmDataAccessBase CreateDataAccessObject(string dataAccessClassName)
{
return new daUserPrefs();
}

---------------------------------------------------------------------------
Here is the specific method in the busUserPrefs class that returns the data
I think I may be doing something wrong here - but am not sure what. The
data loads and binds correctly. Using mm textboxes and combo boxes so far.
---------------------------------------------------------------------------

public DataSet GetPrefbyUserID(int id)
{
// Get a reference to the data access object
mmDataAccessBase dao = this.GetDataAccessObject();

// Create a parameter object for the current user
//IDbDataParameter param1 = dao.CreateParameter("@iuser", id);
IDbDataParameter param1 = dao.CreateParameter("@iuserpref", id);


// Return list of the users preference sets

// DataSet dstemp = this.GetDataSet("dp_UserprefsList",CommandType.StoredProcedure,param1);
DataSet dstemp = this.GetDataSet("dp_UserprefsSelect",CommandType.StoredProcedure,param1);
return dstemp;
}


---------------------------------------------------------------------------
The Data Access Class after my modifications looks like this. Note that I
am not using it as a component - maybe that is the problem. Also note that
I got rid of the connection information. This does not seem to be a problem
as the business object is still getting one using the standard MM.Net way
of getting connections.
---------------------------------------------------------------------------

using System;
using System.Data;
using OakLeaf.MM.Main.Data;

namespace FOI.QuickQuote.Business
{
///
/// Summary description for daUserPrefs.
///

public class daUserPrefs : mmDataAccessSql
{

#region Variable Delcarations
private System.Data.SqlClient.SqlDataAdapter sqlDataAdapter1;
private System.Data.SqlClient.SqlCommand sqlSelectCommand1;
private System.Data.SqlClient.SqlCommand sqlInsertCommand1;
private System.Data.SqlClient.SqlCommand sqlUpdateCommand1;
private System.Data.SqlClient.SqlCommand sqlDeleteCommand1;
// private System.Data.SqlClient.SqlConnection sqlConnection1;
#endregion

#region Constructor
public daUserPrefs()
{
this.ConfigureAdapter();


}
#endregion

#region Override Data Adapter Creation
public override System.Data.IDataAdapter CreateDataAdapter()
{
return this.sqlDataAdapter1;
}
#endregion

#region Configure Adapter
private void ConfigureAdapter()
{
this.sqlDataAdapter1 = new System.Data.SqlClient.SqlDataAdapter();
this.sqlSelectCommand1 = new System.Data.SqlClient.SqlCommand();
this.sqlInsertCommand1 = new System.Data.SqlClient.SqlCommand();
this.sqlUpdateCommand1 = new System.Data.SqlClient.SqlCommand();
this.sqlDeleteCommand1 = new System.Data.SqlClient.SqlCommand();
//this.sqlConnection1 = new System.Data.SqlClient.SqlConnection();
//
// sqlDataAdapter1
//
this.sqlDataAdapter1.DeleteCommand = this.sqlDeleteCommand1;
this.sqlDataAdapter1.InsertCommand = this.sqlInsertCommand1;
this.sqlDataAdapter1.SelectCommand = this.sqlSelectCommand1;
this.sqlDataAdapter1.TableMappings.AddRange(new System.Data.Common.DataTableMapping[]
{ new System.Data.Common.DataTableMapping("Table", "dp_UserprefsSelect",
new System.Data.Common.DataColumnMapping[] {
new System.Data.Common.DataColumnMapping("iuserpref", "iuserpref"),
new System.Data.Common.DataColumnMapping("iuser", "iuser"),
new System.Data.Common.DataColumnMapping("cprefsetname", "cprefsetname"),
new System.Data.Common.DataColumnMapping("bdefault", "bdefault"),
new System.Data.Common.DataColumnMapping("cdefsex", "cdefsex"),
new System.Data.Common.DataColumnMapping("idefage", "idefage"),
new System.Data.Common.DataColumnMapping("iwarningstyle", "iwarningstyle"),
new System.Data.Common.DataColumnMapping("istartuppref", "istartuppref"),
new System.Data.Common.DataColumnMapping("ccertterm", "ccertterm"),
new System.Data.Common.DataColumnMapping("clifeterm", "clifeterm"),
new System.Data.Common.DataColumnMapping("ideferaltype", "ideferaltype"),
new System.Data.Common.DataColumnMapping("cdeffreq", "cdeffreq"),
new System.Data.Common.DataColumnMapping("cdefmode", "cdefmode"),
new System.Data.Common.DataColumnMapping("rowts", "rowts")})});
this.sqlDataAdapter1.UpdateCommand = this.sqlUpdateCommand1;
//
// sqlSelectCommand1
//
this.sqlSelectCommand1.CommandText = "[dp_UserprefsSelect]";
this.sqlSelectCommand1.CommandType = System.Data.CommandType.StoredProcedure;
//this.sqlSelectCommand1.Connection = this.sqlConnection1;
this.sqlSelectCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@RETURN_VALUE", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.ReturnValue, false, ((System.Byte)(0)), ((System.Byte)(0)), "", System.Data.DataRowVersion.Current, null));
this.sqlSelectCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@iuserpref", System.Data.SqlDbType.Int, 4));
//
// sqlInsertCommand1
//
this.sqlInsertCommand1.CommandText = "[dp_UserprefsInsert]";
this.sqlInsertCommand1.CommandType = System.Data.CommandType.StoredProcedure;
//this.sqlInsertCommand1.Connection = this.sqlConnection1;
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@RETURN_VALUE", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.ReturnValue, false, ((System.Byte)(0)), ((System.Byte)(0)), "", System.Data.DataRowVersion.Current, null));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@iuserpref", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.Output, false, ((System.Byte)(0)), ((System.Byte)(0)), "iuserpref", System.Data.DataRowVersion.Current, null));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@iuser", System.Data.SqlDbType.Int, 4, "iuser"));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@cprefsetname", System.Data.SqlDbType.VarChar, 50, "cprefsetname"));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@bdefault", System.Data.SqlDbType.Bit, 1, "bdefault"));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@cdefsex", System.Data.SqlDbType.VarChar, 1, "cdefsex"));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@idefage", System.Data.SqlDbType.Int, 4, "idefage"));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@iwarningstyle", System.Data.SqlDbType.Int, 4, "iwarningstyle"));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@istartuppref", System.Data.SqlDbType.Int, 4, "istartuppref"));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@ccertterm", System.Data.SqlDbType.VarChar, 12, "ccertterm"));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@clifeterm", System.Data.SqlDbType.VarChar, 12, "clifeterm"));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@ideferaltype", System.Data.SqlDbType.Int, 4, "ideferaltype"));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@cdeffreq", System.Data.SqlDbType.VarChar, 2, "cdeffreq"));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@cdefmode", System.Data.SqlDbType.VarChar, 2, "cdefmode"));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@rowts", System.Data.SqlDbType.VarBinary, 8, System.Data.ParameterDirection.Output, false, ((System.Byte)(0)), ((System.Byte)(0)), "rowts", System.Data.DataRowVersion.Current, null));
//
// sqlUpdateCommand1
//
this.sqlUpdateCommand1.CommandText = "[dp_UserprefsUpdate]";
this.sqlUpdateCommand1.CommandType = System.Data.CommandType.StoredProcedure;
//this.sqlUpdateCommand1.Connection = this.sqlConnection1;
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@RETURN_VALUE", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.ReturnValue, false, ((System.Byte)(0)), ((System.Byte)(0)), "", System.Data.DataRowVersion.Current, null));
// this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@iuserpref", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.Output, false, ((System.Byte)(0)), ((System.Byte)(0)), "iuserpref", System.Data.DataRowVersion.Current, null));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@iuserpref", System.Data.SqlDbType.Int, 4, "iuserpref"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@iuser", System.Data.SqlDbType.Int, 4, "iuser"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@cprefsetname", System.Data.SqlDbType.VarChar, 50, "cprefsetname"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@bdefault", System.Data.SqlDbType.Bit, 1, "bdefault"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@cdefsex", System.Data.SqlDbType.VarChar, 1, "cdefsex"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@idefage", System.Data.SqlDbType.Int, 4, "idefage"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@iwarningstyle", System.Data.SqlDbType.Int, 4, "iwarningstyle"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@istartuppref", System.Data.SqlDbType.Int, 4, "istartuppref"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@ccertterm", System.Data.SqlDbType.VarChar, 12, "ccertterm"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@clifeterm", System.Data.SqlDbType.VarChar, 12, "clifeterm"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@ideferaltype", System.Data.SqlDbType.Int, 4, "ideferaltype"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@cdeffreq", System.Data.SqlDbType.VarChar, 2, "cdeffreq"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@cdefmode", System.Data.SqlDbType.VarChar, 2, "cdefmode"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@rowts", System.Data.SqlDbType.VarBinary, 8, System.Data.ParameterDirection.Output, false, ((System.Byte)(0)), ((System.Byte)(0)), "rowts", System.Data.DataRowVersion.Current, null));
//
// sqlDeleteCommand1
//
this.sqlDeleteCommand1.CommandText = "[dp_UserprefsDelete]";
this.sqlDeleteCommand1.CommandType = System.Data.CommandType.StoredProcedure;
//this.sqlDeleteCommand1.Connection = this.sqlConnection1;
this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@RETURN_VALUE", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.ReturnValue, false, ((System.Byte)(0)), ((System.Byte)(0)), "", System.Data.DataRowVersion.Current, null));
this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@iuserpref", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "iuserpref", System.Data.DataRowVersion.Original, null));
//
// sqlConnection1
//


}
#endregion
}
}
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform