Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Method Design Question
Message
 
À
13/02/2009 13:18:46
Mike Cole
Yellow Lab Technologies
Stanley, Iowa, États-Unis
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Divers
Thread ID:
01381477
Message ID:
01381652
Vues:
21
What do you use?


>I don't use DataSet and DataAdapters anymore, so I'm probably not very qualified to answer.
>
>>No worries.
>>
>>I included the param, and it works fine.
>>
>>
>>Please see my next msg about DataSet and DataAdapter. I could use your input.
>>
>>
>>
>>
>>>I need to proofread my messages. I meant to say "I don't see why you couldn't include...".
>>>
>>>>Thanks Mike,
>>>>
>>>>
>>>>
>>>>>Well, you could always test the value of sCommand to see if it begins with "usp_", but that means you would have to be consistent, and I think that would be less desirable than using another param. Other than that that I really have no clue how you would do this. Maybe have two different methods: one designed for running a sql statement and one designed for a Stored Procedure?
>>>>>
>>>>>I don't see why you could include a parameter of type SqlCommandType. The SqlCommand classes do.
>>>>>
>>>>>>I was hoping to avoid another param.
>>>>>>
>>>>>>
>>>>>>>You can simply add one extra parameter that will tell you what you're running. You can default it to SP and use an overload, so your other calls to this method will work as is.
>>>>>>>
>>>>>>>>In my Data Class I have the ExecuteQuery method shown below. It's possible to pass as 'sCommand' either a SELECT command or a stored procedure name.
>>>>>>>>
>>>>>>>>The question is, how do I tell the method that 'sCommand contains a sproc vs. a transaction statement?
>>>>>>>>
>>>>>>>>
>>>>>>>>public DataSet ExecuteQuery(string sCommand, string sTableName, SqlParameter[] colParameters)
>>>>>>>>{
>>>>>>>>    SqlCommand oCommand = _GetCommand(sCommand);
>>>>>>>>    SqlConnection oConn = _GetConnection(false);
>>>>>>>>
>>>>>>>>    if (sTableName == "")
>>>>>>>>    {
>>>>>>>>        sTableName = "";
>>>>>>>>    }
>>>>>>>>
>>>>>>>>    if (colParameters != null)
>>>>>>>>    {
>>>>>>>>        oCommand.Parameters.Clear();
>>>>>>>>        oCommand.Parameters.AddRange(colParameters);
>>>>>>>>        oCommand.CommandType = CommandType.StoredProcedure;
>>>>>>>>    }
>>>>>>>>
>>>>>>>>    
>>>>>>>>    DataSet oDataSet = new DataSet();
>>>>>>>>    _oAdapter = new SqlDataAdapter(sCommand, oConn);
>>>>>>>>
>>>>>>>>    SqlCommandBuilder oBuilder = new SqlCommandBuilder(_oAdapter);
>>>>>>>>
>>>>>>>>    _oAdapter.SelectCommand = oCommand;
>>>>>>>>
>>>>>>>>    try
>>>>>>>>    {
>>>>>>>>        _oAdapter.Fill(oDataSet, sTableName);
>>>>>>>>
>>>>>>>>    }
>>>>>>>>
>>>>>>>>    return oDataSet;
>>>>>>>>}
>>>>>>>>
>>>>>>>>
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