Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
C# ADO Executing Stored Procedure Problem
Message
 
À
18/01/2009 11:11:13
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Divers
Thread ID:
01374697
Message ID:
01374796
Vues:
9
It's amazing how well my code works when I code it right! Thanks.

A related question. Here's the sproc I tested with:
SELECT	prj.ProjectKey, prj.ProjectName, prj.TotalHours, prj.PercentDone, 
		prj.PriorityKey, pri.PriorityName, 
		prj.StatusKey, pst.PrjStatusCodeName,
		prj.ManagerKey, emp.FirstName + ' ' + emp.LastName AS AssignedTo, prj.EstEndDate,
		mod.ModuleKey, mod.ModuleName, mod.ModuleCode, mod.ModuleTypeKey, mt.ModuleTypeName,
		tsk.TaskKey, tsk.TaskName, tsk.TotalHours AS TaskTotalHours, tsk.PercentDone AS TaskPercentDone, 
		tsk.PriorityKey AS TaskPriorityKey, tpr.PriorityName AS TaskPriority,
		tsk.AssignedEmpKey AS TaskAssignedToKey, temp.FirstName + ' ' + temp.LastName AS TaskAssignedTo
	FROM bm_Projects prj
	FULL JOIN bm_Employees emp ON emp.EmployeeKey = prj.ManagerKey
	FULL JOIN bm_Priorities pri ON pri.PriorityKey = prj.PriorityKey
	FULL JOIN bm_ProjectStatusCodes pst ON pst.PrjStatusCodeKey = prj.StatusKey
	FULL JOIN bm_Modules mod ON mod.ProjectKey = prj.ProjectKey
	FULL JOIN bm_ModuleTypes mt ON mt.ModuleTypeKey = mod.ModuleTypeKey
	FULL JOIN bm_Tasks tsk ON tsk.ModuleKey = mod.ModuleKey
	FULL JOIN bm_Priorities tpr ON tpr.PriorityKey = tsk.PriorityKey
	FULL JOIN bm_Employees temp ON temp.EmployeeKey = tsk.AssignedEmpKey
	WHERE prj.AppKey = @AppKey
I don't understand how ADO can make changes to the underlying table. I mean, in the resulting DS, assume I change the value of
ModuleTypeKey, which is in a JOINed table. If I then call Update, how does ADO know which table to put the changes in? If I had to guess, I would say that it parses the query and stores all the table name and other info, but this all seems really complicated.

I guess I'm wondering if you could shed a bit of light on this.

Thanks




>Hi Kevin,
>
>You've left out the name of the parameter, which I assume you want to be the same as the column name. You need to add something like this to your ExecuteStoredProc class:
>
>
>oParam.ParameterName = "@" +  oColParam.sSrcColName;
>
>
>~~Bonnie
>
>
>>I posted something similar a while back, and I still cant get this to work.
>>
>>I wrote a data access class. It has an ExecuteStoredProc method which accepts a class that contains all the necessaru info, such as the name of the sproc and a collection of params to pass to SQL.
>>
>>I'm getting the exception "@Parameter1 is not a parameter for procedure bm_GetAppOverview."
>>
>>I run it like this. As you can see, I specified the parameter column name as "AppKey". Anyone know what's happening?
>>
>>
>>static void Main(string[] args)
>>{
>>    DataAccess oDataAccess = new DataAccess();
>>
>>    oDataAccess.Provider = DataAccess.ProviderType.SQL;
>>    oDataAccess.ConnectionString = sConnString;
>>
>>
>>    // Paramaters collection object
>>    DataAccess.ProcedureParams oParams = new DataAccess.ProcedureParams();
>>    oParams.sProcedureName = "bm_GetAppOverview";
>>
>>    // Create param objects and add to the collection
>>    DataAccess.Param oAppKey = new DataAccess.Param();
>>    oAppKey.Direction = System.Data.ParameterDirection.Input;
>>    oAppKey.iSize = 0;
>>    oAppKey.sSrcColName = "AppKey";
>>    oAppKey.value = 0;
>>
>>    oParams.AddParam(oAppKey);
>>
>>    // Call into the data access class & run the sproc
>>    DataSet oData = oDataAccess.ExecuteStoredProc(oParams);
>>}
>>
>>
>>Here's the ExecuteStoredProc code:
>>
>>
>>public DataSet ExecuteStoredProc(ProcedureParams oParams)
>>{
>>    DataSet oDataSet = new DataSet();;
>>
>>    IDbCommand oCommand = _GetCommand(oParams.sProcedureName);
>>
>>    if (oCommand != null)
>>    {
>>        oCommand.CommandType = CommandType.StoredProcedure;
>>
>>        foreach (Param oColParam in oParams.Params)
>>        {
>>            SqlParameter oParam = new SqlParameter();
>>
>>            oParam.DbType = oColParam.Type;
>>            oParam.Direction = oColParam.Direction;
>>            oParam.SourceColumn = oColParam.sSrcColName;
>>            oParam.Size = oColParam.iSize;
>>            oParam.Value = oColParam.value;
>>
>>            oCommand.Parameters.Add(oParam);
>>        }
>>
>>        IDbDataAdapter oAdapter = _GetDataAdapter(oParams.sProcedureName);
>>
>>        if (oAdapter != null)
>>        {
>>
>>            oAdapter.SelectCommand = oCommand;
>>
>>            try
>>            {
>>                oAdapter.Fill(oDataSet);
>>
>>            }
>>            catch (SqlException e)
>>            {
>>                // Removed for brevity
>>            }
>>        }
>>    }
>>    return oDataSet;
>>
>>
>>
>>I know the _GetCommand and _GetDataAdapter methods work because they are already in use elsewhere.
Everything makes sense in someone's mind
public class SystemCrasher :ICrashable
In addition, an integer field is not for irrational people
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform