当前位置: 首页>>代码示例>>C#>>正文


C# SqlClient.SqlParameterCollection类代码示例

本文整理汇总了C#中System.Data.SqlClient.SqlParameterCollection的典型用法代码示例。如果您正苦于以下问题:C# SqlParameterCollection类的具体用法?C# SqlParameterCollection怎么用?C# SqlParameterCollection使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


SqlParameterCollection类属于System.Data.SqlClient命名空间,在下文中一共展示了SqlParameterCollection类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: LocalCommand

 internal LocalCommand(string commandText, SqlParameterCollection parameters,  int returnParameterIndex, CommandType cmdType) {
     Debug.Assert(0 <= commandText.Length, "no text");
     this.CommandText = commandText;
     this.Parameters = parameters;
     this.ReturnParameterIndex = returnParameterIndex;
     this.CmdType = cmdType;
 }
开发者ID:nlh774,项目名称:DotNetReferenceSource,代码行数:7,代码来源:SqlCommandSet.cs

示例2: GenericStatementReturnDataSet

        public DataSet GenericStatementReturnDataSet(string strStoredProcedure, SqlParameterCollection sqlparCollection)
        {
            DataSet ds = new DataSet();
            try
            {
                OpenConnection();
                sqlcmd = new SqlCommand(strStoredProcedure, sqlcon);
                sqlcmd.CommandType = CommandType.StoredProcedure;

                foreach (SqlParameter param in sqlparCollection)
                {
                    sqlcmd.Parameters.AddWithValue(param.ParameterName, param.SqlValue);
                }

                sqlAdp = new SqlDataAdapter(sqlcmd);
                sqlAdp.Fill(ds);
                CloseConnection();
            }
            catch (Exception ex)
            {
                CloseConnection();
                cErrorLog.LogError(ex);
            }
            return ds;
        }
开发者ID:swapneshpal,项目名称:HRIMS,代码行数:25,代码来源:cBaseHelper.cs

示例3: PersistAddExtraParameters

        public override void PersistAddExtraParameters(SqlParameterCollection parameters, Employee employee)
        {
            var emp = employee as EmployeeFullTime;

            if (emp != null)
            {
                parameters.AddWithValue("@AnnualSalary", emp.AnnualSalary);
            }
        }
开发者ID:cesaroll,项目名称:WCF_Employee,代码行数:9,代码来源:EmployeeFullTimeFactory.cs

示例4: DumpSqlParameters

        /// <summary>
        /// Iterates through a SqlParameterCollection to output the names and values in one line.
        /// </summary>
        /// <param name="sqlParameterCollection"></param>
        /// <returns></returns>
        public static string DumpSqlParameters(SqlParameterCollection sqlParameterCollection)
        {
            var buffer = new StringBuilder();
            foreach (SqlParameter p in sqlParameterCollection)
            {
                buffer.Append('{').Append("param_name=").Append(p.ParameterName).Append(',');
                buffer.Append("param_value=").Append(p.Value).Append('}');
            }

            return buffer.ToString();
        }
开发者ID:hoserdude,项目名称:buche-dot-net,代码行数:16,代码来源:LogUtil.cs

示例5: CopyParameters

 internal static IEnumerable<SqlParameter> CopyParameters( SqlParameterCollection sqlParameterCollection )
 {
     foreach ( SqlParameter sqlParameter in sqlParameterCollection )
     {
         yield return new SqlParameter( sqlParameter.ParameterName, sqlParameter.SqlValue )
         {
             SqlValue = sqlParameter.SqlValue
             //, Direction = sqlParameter.Direction
         };
     }
 }
开发者ID:zacwhy,项目名称:MvcExpense,代码行数:11,代码来源:UnitOfWorkBaseHelper.cs

示例6: PersistAddExtraParameters

        public override void PersistAddExtraParameters(SqlParameterCollection parameters, Employee employee)
        {
            var emp = employee as EmployeePartTime;

            if (emp != null)
            {
                parameters.AddWithValue("@HourlyPay", emp.HourlyPay);
                parameters.AddWithValue("@HoursWorked", emp.HoursWorked);
            }

        }
开发者ID:cesaroll,项目名称:WCF_Employee,代码行数:11,代码来源:EmployeePartTimeFactory.cs

示例7: AddSerializedProperty

 private static void AddSerializedProperty(ArraySegment<byte> source, SqlParameterCollection parameters, string parameterName)
 {
     int num = (source.Count > 0x1f40) ? source.Count : -1;
     object obj2 = ((num == -1) ? ((bool) GenerateByteArray(source)) : ((bool) source.Array)) ?? DBNull.Value;
     SqlParameter parameter = new SqlParameter {
         ParameterName = parameterName,
         SqlDbType = SqlDbType.VarBinary,
         Size = num,
         Value = obj2
     };
     parameters.Add(parameter);
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:12,代码来源:SaveWorkflowAsyncResult.cs

示例8: ExecuteInsert

        public int ExecuteInsert(string sProc, SqlParameterCollection oArrParam)
        {
            int iRecordsAffected = 0;
                if (CheckDBConnStatus() == true)
                {
                    SqlTransaction oTrans;
                    oTrans = oConn.BeginTransaction();

                    try
                    {

                        SqlCommand oCmd = new SqlCommand(sProc, oConn, oTrans);
                        oCmd.CommandType = CommandType.StoredProcedure;

                        foreach (SqlParameter oParam in oArrParam)
                        {
                            oCmd.Parameters.Add(oParam.ParameterName, oParam.SqlDbType).Value = oParam.Value;
                        }

                        iRecordsAffected = oCmd.ExecuteNonQuery();
                        oTrans.Commit();

                        oTrans.Dispose();
                        oTrans = null;
                        oCmd.Dispose();
                        oCmd = null;

                        oConn.Close();
                        return iRecordsAffected;

                    }
                    catch (SqlException sqlerr)
                    {
                        oTrans.Rollback();
                        sErrMessage = "SQL Error: Number - " + sqlerr.Number + ", " + sqlerr.Message;
                        return iRecordsAffected;

                    }

                    catch (Exception err)
                    {
                        oTrans.Rollback();
                        sErrMessage = " Runtime Error: " + err.Message;
                        return iRecordsAffected;
                    }
                }
                else
                {
                    return iRecordsAffected;
                }
        }
开发者ID:DevOps-SFDC,项目名称:GPH,代码行数:51,代码来源:DbInterface.cs

示例9: CapNhatBanGhi

 /// <summary>
 /// cập nhật chứng từ
 /// </summary>
 /// <param name="iID_MaCapPhat"></param>
 /// <param name="Params"></param>
 /// <param name="sMaND"></param>
 /// <param name="sIPSua"></param>
 /// <returns></returns>
 public static Boolean CapNhatBanGhi(String iID_MaCapPhat, SqlParameterCollection Params, String sMaND, String sIPSua)
 {
     Bang bang = new Bang("CP_CapPhat");
     bang.MaNguoiDungSua = sMaND;
     bang.IPSua = sIPSua;
     bang.GiaTriKhoa = iID_MaCapPhat;
     bang.DuLieuMoi = false;
     for (int i = 0; i < Params.Count; i++)
     {
         bang.CmdParams.Parameters.AddWithValue(Params[i].ParameterName, Params[i].Value);
     }
     bang.Save();
     return false;
 }
开发者ID:BMSProject2015,项目名称:BMS,代码行数:22,代码来源:CapPhat_ChungTuModels.cs

示例10: BuildQueryParameters

		private static void BuildQueryParameters (IDbCommand cmd,SqlParameterCollection parameterCollection){
		                                         
			if (parameterCollection != null && parameterCollection.Count > 0) {
				foreach (SqlParameter par in  parameterCollection) {
					var cmdPar = cmd.CreateParameter();
					cmdPar.ParameterName = par.ParameterName;
					if (par.DataType != System.Data.DbType.Binary) {
						cmdPar.DbType = par.DataType;
						cmdPar.Value = par.ParameterValue;

					} else {
						cmdPar.DbType = System.Data.DbType.Binary;
					}
					cmdPar.Direction = par.ParameterDirection;
					cmd.Parameters.Add(cmdPar);
				}
			}
		}
开发者ID:Paccc,项目名称:SharpDevelop,代码行数:18,代码来源:SqlDataAccess.cs

示例11: ExecuteInsertWithIdentity

        public SqlDataReader ExecuteInsertWithIdentity(string sProc, SqlParameterCollection oArrParam)
        {
            SqlDataReader oRd = null;
                if (CheckDBConnStatus() == true)
                {
                    try
                    {
                        SqlCommand oCmd = new SqlCommand(sProc, oConn);
                        oCmd.CommandType = CommandType.StoredProcedure;

                        foreach (SqlParameter oParam in oArrParam)
                        {
                            oCmd.Parameters.Add(oParam.ParameterName, oParam.SqlDbType).Value = oParam.Value;
                        }

                        if (oConn.State == ConnectionState.Closed)
                        {
                            oConn.ConnectionString = this.FGetConnString();
                            oConn.Open();
                        }

                        oRd = oCmd.ExecuteReader();
                        return oRd;
                    }
                    catch (SqlException sqlerr)
                    {
                        sErrMessage = "SQL Error: Number - " + sqlerr.Number + ", " + sqlerr.Message;
                        return oRd;

                    }

                    catch (Exception err)
                    {
                        sErrMessage = " Runtime Error: " + err.Message;
                        return oRd;
                    }
                }
                else
                {
                    return oRd;
                }
        }
开发者ID:DevOps-SFDC,项目名称:GPH,代码行数:42,代码来源:DbInterface.cs

示例12: ExecuteNonQuery

 public void ExecuteNonQuery(string sqlText, SqlParameterCollection spc)
 {
     try
     {
         if (objConn.State != ConnectionState.Open)
         {
             OpenConnection();
         }
         this.cm = new SqlCommand(sqlText, this.objConn);
         foreach (SqlParameter sp in spc)
         {
             this.cm.Parameters.Add(sp);
         }
         cm.ExecuteNonQuery();
     }
     catch (Exception e)
     {
         throw new Exception("Error in ExecuteQuery!!! Source:" + e.Source.ToString() + " Message:" + e.Message.ToString());
     }
 }
开发者ID:2hanson,项目名称:yahoohackbj,代码行数:20,代码来源:DataControlDB.cs

示例13: Append

        internal void Append(SqlCommand command) {
            ADP.CheckArgumentNull(command, "command");
            Bid.Trace("<sc.SqlCommandSet.Append|API> %d#, command=%d, parameterCount=%d\n", ObjectID, command.ObjectID, command.Parameters.Count);

            string cmdText = command.CommandText;
            if (ADP.IsEmpty(cmdText)) {
                throw ADP.CommandTextRequired(ADP.Append);
            }

            CommandType commandType = command.CommandType;
            switch(commandType) {
            case CommandType.Text:
            case CommandType.StoredProcedure:
                break;
            case CommandType.TableDirect:
                Debug.Assert(false, "command.CommandType");
                throw System.Data.SqlClient.SQL.NotSupportedCommandType(commandType);
            default:
                Debug.Assert(false, "command.CommandType");
                throw ADP.InvalidCommandType(commandType);
            }

            SqlParameterCollection parameters = null;

            SqlParameterCollection collection = command.Parameters;
            if (0 < collection.Count) {
                parameters = new SqlParameterCollection();

                // clone parameters so they aren't destroyed
                for(int i = 0; i < collection.Count; ++i) {
                    SqlParameter p = new SqlParameter();
                    collection[i].CopyTo(p);
                    parameters.Add(p);

                    // SQL Injection awarene
                    if (!SqlIdentifierParser.IsMatch(p.ParameterName)) {
                        throw ADP.BadParameterName(p.ParameterName);
                    }
                }

                foreach(SqlParameter p in parameters) {
                    // deep clone the parameter value if byte[] or char[]
                    object obj = p.Value;
                    byte[] byteValues = (obj as byte[]);
                    if (null != byteValues) {
                        int offset = p.Offset;
                        int size = p.Size;
                        int countOfBytes = byteValues.Length - offset;
                        if ((0 != size) && (size < countOfBytes)) {
                            countOfBytes = size;
                        }
                        byte[] copy = new byte[Math.Max(countOfBytes, 0)];
                        Buffer.BlockCopy(byteValues, offset, copy, 0, copy.Length);
                        p.Offset = 0;
                        p.Value = copy;
                    }
                    else {
                        char[] charValues = (obj as char[]);
                        if (null != charValues) {
                            int offset = p.Offset;
                            int size = p.Size;
                            int countOfChars = charValues.Length - offset;
                            if ((0 != size) && (size < countOfChars)) {
                                countOfChars = size;
                            }
                            char[] copy = new char[Math.Max(countOfChars, 0)];
                            Buffer.BlockCopy(charValues, offset, copy, 0, copy.Length*2);
                            p.Offset = 0;
                            p.Value = copy;
                        }
                        else {
                            ICloneable cloneable = (obj as ICloneable);
                            if (null != cloneable) {
                                p.Value = cloneable.Clone();
                            }
                        }
                    }
                }
            }

            int returnParameterIndex = -1;
            if (null != parameters) {
                for(int i = 0; i < parameters.Count; ++i) {
                    if (ParameterDirection.ReturnValue == parameters[i].Direction) {
                        returnParameterIndex = i;
                        break;
                    }
                }
            }
            LocalCommand cmd = new LocalCommand(cmdText, parameters, returnParameterIndex, command.CommandType);
            CommandList.Add(cmd);
        }
开发者ID:nlh774,项目名称:DotNetReferenceSource,代码行数:92,代码来源:SqlCommandSet.cs

示例14: FormatParameters

		private static string FormatParameters (SqlParameterCollection sqlParameterCollection) 
		{
			StringBuilder sb = new StringBuilder ();
			foreach (SqlParameter p in sqlParameterCollection) {
				if (sb.Length > 0) {
					sb.Append (", ");
				}
				sb.AppendFormat ("{0}:{1}={2}", p.DbType, p.ParameterName, p.Value);
			}
			return sb.ToString ();
		}
开发者ID:Profit0004,项目名称:mono,代码行数:11,代码来源:SqlDataSourceViewTest.cs

示例15: SetParameter

 static void SetParameter(IEdmFunction func, JObject parameterValues, IEdmType edmType, SqlParameterCollection pars)
 {
     if (parameterValues == null)
         return;
     JToken token = null;
     Type colType = null;
     foreach (var p in func.Parameters)
     {
         if (parameterValues.TryGetValue(p.Name, out token))
         {
             if (p.Type.Definition.TypeKind == EdmTypeKind.Complex)
             {
                 DataTable dt = new DataTable();
                 var c = p.Type.AsComplex();
                 foreach (var item in c.StructuralProperties())
                 {
                     dt.Columns.Add(item.Name, item.Type.PrimitiveKind().ToClrType());
                 }
                 foreach (var item in token)
                 {
                     DataRow dr = dt.NewRow();
                     foreach (JProperty col in item)
                     {
                         if (!dt.Columns.Contains(col.Name))
                             continue;
                         colType = dt.Columns[col.Name].DataType;
                         if (colType == typeof(Boolean))
                         {
                             dr.SetField(col.Name, col.Value.ToString() == "0" ? false : true);
                         }
                         else
                             dr.SetField(col.Name, col.Value.ToString().ChangeType(colType));
                     }
                     dt.Rows.Add(dr);
                 }
                 pars.AddWithValue(p.Name, dt);
             }
             else
             {
                 if (string.IsNullOrEmpty(token.ToString()))
                     pars.AddWithValue(p.Name, DBNull.Value);
                 else
                     pars.AddWithValue(p.Name, token.ToString().ChangeType(p.Type.PrimitiveKind()));
             }
         }
     }
     if (edmType.TypeKind == EdmTypeKind.Entity)
     {
         foreach (var outp in (edmType as EdmEntityType).Properties())
         {
             if (outp.Name == "$Results")
                 continue;
             if (pars.Contains(outp.Name))
             {
                 pars[outp.Name].Direction = ParameterDirection.Output;
             }
             else
             {
                 pars.AddWithValue(outp.Name, DBNull.Value);
             }
         }
     }
 }
开发者ID:maskx,项目名称:OData,代码行数:63,代码来源:SQLDataSource.cs


注:本文中的System.Data.SqlClient.SqlParameterCollection类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。