Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
SP as Adapter SelectCommand
Message
Information générale
Forum:
ASP.NET
Catégorie:
ADO.NET
Versions des environnements
Environment:
C# 1.1
Database:
MS SQL Server
Divers
Thread ID:
01077893
Message ID:
01077940
Vues:
44
>>>I had a thought when I woke up this morning. Can I pass a SP as an Adapter's SelectCommand?
>>>If it is possible are there any advantages/disadvantages for doing this?
>>>
>>>Einar
>>
>>I may not understand your question but here is something that I do.
>>
>>I have a Class that controls my data handling. When I use a DataAdapter I call a SP. Now as for advantages/disadvantages, I am guessing that allowing the SP to do “the work” would be better.
>
>I think you understand my question.
>This is in a nut-shell what I want to do:
>
>oleDbAdapter = new OleDbDataAdapter();
>oleDbAdapter.SelectCommand = new OleDbCommand("MyStoredProcedureName", oleDbConnection);
>oleDbAdapter.Fill(myDataset, "myTable");
>
>
>I realize how easy it would be for me to test this, but I just wanted to check here before I dove into that.
>
Einar

Here is an example of something I use. I have a seperate Connection Class as you can see below. Needless to say that my code is for SQL Server! :)
public class ScrapConnection
	{
			public static SqlConnection GetConnection() 
			{
					string connectionString = ConfigurationSettings.AppSettings["connectionString"];
		
					return new SqlConnection(connectionString);	
				

			}	
	}


public static DataSet FindUser(string UserID)
		{
			// Return a DataSet using a Stored Procedure...
			SqlDataAdapter daUser = new SqlDataAdapter();
			
			SqlParameter UserParm1 = new SqlParameter("@UserID", SqlDbType.Char,25);
			UserParm1.Direction = ParameterDirection.Input;
			UserParm1.Value = UserID;

			
			daUser.SelectCommand = new SqlCommand();
			daUser.SelectCommand.Connection = ScrapConnection.GetConnection();
			daUser.SelectCommand.CommandText = "GetUser";
			daUser.SelectCommand.CommandType= CommandType.StoredProcedure;
			daUser.SelectCommand.Parameters.Add(UserParm1);

			DataSet dsUser = new DataSet();
			daUser.Fill(dsUser,"UserID");
			ScrapConnection.GetConnection().Close(); // 11-17-2004
			
			return dsUser;
		}
Tom
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform