回答

收藏

使用我的存储过程时出现问题

技术问答 技术问答 376 人阅读 | 0 人回复 | 2023-09-11

我的以下方法应该是我的应用程序的通用“保存到SQL”方法。6 j% z2 S/ s/ A; C
protected void EjecutarGuardar(string ProcedimientoAlmacenado, object[] Parametros)/ C3 o8 k3 t. Y  T5 W
        {
8 P/ W: F4 w+ h  A% f/ f* M            SqlConnection Connection = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
4 a% f9 Q/ y3 ]6 n. i            SqlCommand Command = Connection.CreateCommand();             1 D$ q1 D& A( a' y; l* O3 b& ]5 d
            Command.CommandType = CommandType.StoredProcedure;  [$ B9 _& r2 ~: h0 k& G2 u
            foreach (object X in Parametros)( L7 e" G" F3 |" @+ i/ T
            {
+ g* N1 A$ L- U  T" c                Command.Parameters.Add(X);  Z$ o) f# w( L+ p" E/ J
            }) f- _2 S1 s. C8 {  K& A2 p
            Connection.Open();' w5 {$ d  E' H, v, I- g
            Command.ExecuteNonQuery();/ p! r/ y& [- l( v8 c# I# ^$ L
            Connection.Close();! J( n; t! u- a  M8 h2 {. C
            Connection.Dispose();
+ `6 X# C) ~8 y, a* x( d% d        }+ A8 `# B. K3 L1 |" q
我必须传递StoredProcedure的名称和一个填充有参数的数组。在这一点上,我有点迷茫。我应该在哪里使用存储过程“3 V& n$ I" v# `) D1 C$ O
ProcedimientoAlmacenado”的名称?+ }5 B3 ~- F+ [) F  V
我在想Command.Command ????? 但是我迷路了。有什么帮助吗?3 B3 ^3 x/ s# w) f3 ?1 y
编辑:为简单起见,假设我在数据库中有一个名为“ ABC”的存储过程。如何在我的代码中将其与SqlCommand“ Command”关联?
# `9 ~$ |- }# N* o% I: B! n                + d" g( |2 h2 Z2 a# s& q. _2 z0 b
解决方案:
分享到:
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则