Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Executing Stored Procs With Params
Message
Information générale
Forum:
ASP.NET
Catégorie:
Bases de données
Divers
Thread ID:
00979533
Message ID:
00979535
Vues:
18
Hey, Kevin,

There are a number of ways you can do this. If you have a SQL back-end and want to return the result into a dataset, the following example can work:
string cConnectStr	= "user id=sa;password=;initial catalog=Mydatabase;data source=MyServer"; 
SqlConnection oSqlConn = new SqlConnection(cConnectStr);
DataSet DsMyData = new DataSet();
SqlDataAdapter oSqlAdapter = new SqlDataAdapter(cMyStoredProcName, oSqlConn);

SqlParameter parmID = new SqlParameter("@nCustID",SqlDbType.Int);    // ncustID is the actual parameter name in the SP
parmID.Value = nCustId;    // nCustID is the integer containing the value you want to pass

oSqlAdapter.SelectCommand.CommandType = CommandType.StoredProcedure;
oSqlAdapter.SelectCommand.Parameters.Add(parmID);
oSqlAdapter.Fill( DsMyData,"MyDataSet");
oSqlConn.Close();
Again, there are many different ways, and you'd want to abstract out the connection object handling and other things, but hopefully that should give you an idea. If you had two parameters, you'd create a second parameter object and add it.

Hope that helps,
Kevin
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform