Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Stored Procedures Parameters
Message
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Versions des environnements
Environment:
C# 3.0
OS:
Windows XP SP2
Network:
Windows 2008 Server
Database:
MS SQL Server
Divers
Thread ID:
01359966
Message ID:
01359973
Vues:
28
Ok, here's what I have now:

The app data class has this method:
public DataSet GetProjects(int iAppKey, int iCategoryKey, int iStatusKey)
{
    DataSet oDataSet = null;

    SqlParameter p1 = new SqlParameter("@AppKey", iAppKey);
    SqlParameter p2 = new SqlParameter("@CategoryKey", iCategoryKey);
    SqlParameter p3 = new SqlParameter("@StatusKey", iStatusKey);

    SqlParameter[] ParamArray = new SqlParameter[]{p1, p2, p3};

    oDataSet = oDataAccess.ExecuteQueryProc("bm_GetProjects", ParamArray);

    return oDataSet;
}
Then the SqlDataAccess class's ExecuteQueryProc method:
public DataSet ExecuteQueryProc(string sParameterName, SqlParameter[] ParamArray)
{
    DataSet oDataSet = new DataSet();

    SqlConnection oConn = GetConnection(true);

    if (oConn != null)
    {
        SqlCommand oCommand = new SqlCommand();
        oCommand.Connection = oConn;
        oCommand.CommandText = sParameterName;
        oCommand.CommandType = CommandType.StoredProcedure;

        oCommand.Parameters.AddRange(ParamArray);

        SqlDataAdapter oAdapter = new SqlDataAdapter();
        oAdapter.SelectCommand = oCommand;
        oAdapter.Fill(oDataSet);
    }
    return oDataSet;
}
Although there is alot less code, which I like, I'm still not getting any data. The parameter value are ok.



>Kevin,
>
>Just use add parameters with range. In your other thread I posted code that does exactly that - receives parameters collection.
>
>>This is a bit long but....
>>
>>I have a stand-alone SQLDataAccess class which contains generic methods for calling into MS Sql. It is generic enough so that I can use it in most of my apps.
>>
>>In my app have an AppDataAccess class for handling data access within my app. It is simply a wrapper for calls to the SQLDataAccess and contains specific methods for the stored procedures I will be calling.
>>
>>My SQLDataAccess has a method called 'ExecuteQueryProc' which takes as a parameter a collection class which holds instances of a Params class I wrote which simply mirror SqlParameters.
>>
>>So in AppDataAccess I create as many Param classes as I need, set their parameters, then add them to the Params collection class, which I then pass this to ExecuteQueryProc in SQLDataAccess :
>>
>>
>>
>>// SQLDataAccess. ExecuteQueryProc
>>public DataSet ExecuteQueryProc(ProcedureParams oParams)
>>{
>>DataSet oDataSet = new DataSet();
>>
>>SqlConnection oConn = GetConnection(true);
>>
>>if (oConn != null)
>>{
>>    SqlCommand oCommand = new SqlCommand(oParams.sProcedureName, oConn);
>>    oCommand.CommandType = CommandType.StoredProcedure;
>>
>>    foreach (Param oColParam in oParams.Params)
>>    {
>>        SqlParameter oParam = new SqlParameter();
>>
>>        oParam.DbType = DbType.Int32;
>>        oParam.Direction = ParameterDirection.Input;
>>        oParam.ParameterName = oColParam.sParameterName;
>>        oParam.SourceColumn = oColParam.sSrcColName;
>>        oParam.SqlDbType = SqlDbType.Int;
>>        oParam.Value = oColParam.Value;
>>
>>        oCommand.Parameters.Add(oParam);
>>
>>        oParam = null;
>>    }
>>
>>    SqlDataAdapter oAdapter = new SqlDataAdapter();
>>    oAdapter.SelectCommand = oCommand;
>>    oAdapter.Fill(oDataSet);
>>
>>    return oDataSet;
>>}
>>return oDataSet;
>>
>>
>>Ok, here's the problem. If I code each param individually using native ADO code, I get a data set back. If I use this code above, I get no records. I have walked it through a few times and I cannot see what the problem is. The data being set on the oParam object all appear to be ok.
>>
>>Anyone wanna take a stab it this?
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