Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
C# ADO Executing Stored Procedure Problem
Message
De
19/01/2009 18:10:56
 
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Divers
Thread ID:
01374697
Message ID:
01375296
Vues:
10
>Then the code in the foreach only needs the param info, right?

Yeah, that will work. Just be sure to issue the sc.Parameters.Clear() before setting the parameters for each row.

~~Bonnie




>Ok, I think I see it now...
>
>You wrote:
>
>
>	SqlCommand sc = new SqlCommand();
>	sc.Connection = this.oConnection;
>	sc.Connection.Open();
>	foreach (DataRow Row in ds.Tables[0].Rows)
>	{
>		switch (Row.RowState)
>		{
>			case DataRowState.Added :
>				// or use a StoredProc, which I prefer
>				sc.CommandText = "Insert into bob (xyz, abc) VALUES ( @xyz, @abc )";
>				sc.Parameters.Clear();
>				sc.Parameters.Add("@xyz", Row["xyz"]);
>				sc.Parameters.Add("@abc", Row["abc"]);
>				sc.ExecuteNonQuery();
>				break;
>				
>			// Do the same for DataRowState Deleted and Modified
>			case DataRowState.Deleted :
>				break;
>			case DataRowState.Modified :
>				break;
>		}
>	}
>	sc.Connection.Close();
>
>
>
>But this line...
>
>
>sc.CommandText = "Insert into bob (xyz, abc) VALUES ( @xyz, @abc )";
>
>
>could be up here instead....
>
>
>
>SqlCommand sc = new SqlCommand();
>sc.CommandText = "Insert into bob (xyz, abc) VALUES ( @xyz, @abc )";  <<<---------------
>sc.Connection = this.oConnection;
>sc.Connection.Open();
>foreach (DataRow Row in ds.Tables[0].Rows)
>{
>.
>.
>.
>
>
>Then the code in the foreach only needs the param info, right?
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform