回答

收藏

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

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

我的以下方法应该是我的应用程序的通用“保存到SQL”方法。# ]5 z: E( h8 a" i6 Z
protected void EjecutarGuardar(string ProcedimientoAlmacenado, object[] Parametros)- @9 F& [8 Z) j" U
        {
' |( r7 [2 w$ e' t" E            SqlConnection Connection = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
7 q0 z" C& T: O) V# N            SqlCommand Command = Connection.CreateCommand();            
  |) Q9 F, l0 }/ Z            Command.CommandType = CommandType.StoredProcedure;
$ P: s  ^7 N6 ?            foreach (object X in Parametros)
; X# W7 w. b/ I0 L$ y( Q, _            {: ~  X2 C1 B5 U0 @0 r
                Command.Parameters.Add(X);
1 I0 J# ]7 @' H2 u( w  Q            }  M; P+ y' v3 q9 H( W0 h& f% I
            Connection.Open();
9 Q) y& k% m& Q( x- i            Command.ExecuteNonQuery();0 W9 `) S! o$ F% u- X; h+ k9 ~
            Connection.Close();" h0 W1 {! s/ W  {7 [
            Connection.Dispose();9 w7 a( U* {* k$ ^/ F
        }
9 N3 C+ \& \+ d) P& E/ u' c* s我必须传递StoredProcedure的名称和一个填充有参数的数组。在这一点上,我有点迷茫。我应该在哪里使用存储过程“' j. v; E* `5 x/ V/ E* r
ProcedimientoAlmacenado”的名称?
7 w: p) C/ P7 b' ^我在想Command.Command ????? 但是我迷路了。有什么帮助吗?9 j9 l' T* P" X+ |1 b
编辑:为简单起见,假设我在数据库中有一个名为“ ABC”的存储过程。如何在我的代码中将其与SqlCommand“ Command”关联?; o6 Y' k" Y6 T; B7 y; J; g$ m
                & o" a, N1 ?9 F# {6 R$ u/ e8 T% ]
解决方案:
分享到:
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则