Beispiel #1
0
 public string GetXmlFromArray(Array array)
 {
     return(SqlUtil.GetXmlFromArray(array));
 }
Beispiel #2
0
        private void AddDBParam(SqlCommand cmd, DBParameter dbParam)
        {
            if (dbParam.ParamValue == null)
            {
                AddDBParamNoValue(cmd, dbParam);
                return;
            }
            try
            {
                DBParameterType paramType = dbParam.ParamType;
                switch (paramType)
                {
                case DBParameterType.BoolParam:
                    SqlUtil.AddParam(cmd, dbParam.ParamName, (bool)dbParam.ParamValue); break;

                case DBParameterType.DateTimeParam:
                    SqlUtil.AddParam(cmd, dbParam.ParamName, (DateTime)dbParam.ParamValue); break;

                case DBParameterType.DoubleParam:
                    SqlUtil.AddParam(cmd, dbParam.ParamName, (double)dbParam.ParamValue); break;

                case DBParameterType.IntParam:
                    SqlUtil.AddParam(cmd, dbParam.ParamName, (int)dbParam.ParamValue); break;

                case DBParameterType.NullableIntParam:
                    SqlUtil.AddParam(cmd, dbParam.ParamName, (int?)dbParam.ParamValue); break;

                case DBParameterType.StringParam:
                    SqlUtil.AddParam(cmd, dbParam.ParamName, (string)dbParam.ParamValue); break;

                case DBParameterType.TextParam:
                    SqlUtil.AddParam(cmd, dbParam.ParamName, (string)dbParam.ParamValue, true); break;

                case DBParameterType.XmlParam:
                    SqlUtil.AddParam(cmd, dbParam.ParamName, (string)dbParam.ParamValue, false, true); break;

                case DBParameterType.BytesParam:
                    SqlUtil.AddParam(cmd, dbParam.ParamName, (byte[])dbParam.ParamValue); break;

                case DBParameterType.NcharParam:
                    SqlUtil.AddParam(cmd, dbParam.ParamName, dbParam.ParamValue == null ? new char[0] : ((string)dbParam.ParamValue).ToCharArray()); break;

                case DBParameterType.IntParamOutput:
                    SqlUtil.AddOutputParam(cmd, dbParam.ParamName, paramType);
                    ParameterNames.Add(dbParam.ParamName);
                    break;

                case DBParameterType.StringParamOutput:
                    SqlUtil.AddOutputParam(cmd, dbParam.ParamName, paramType);
                    ParameterNames.Add(dbParam.ParamName);
                    break;

                case DBParameterType.ByteParam:
                    SqlUtil.AddParam(cmd, dbParam.ParamName, (byte)dbParam.ParamValue); break;
                }
            }
#pragma warning disable 168
            catch (System.InvalidCastException whoops)
            {
                // bad data, treat as null...
                AddDBParamNoValue(cmd, dbParam);
            }
#pragma warning restore 168
        }
Beispiel #3
0
 public void CloseReader(IDataReader dr)
 {
     SqlUtil.CloseReader((SqlDataReader)dr);
 }
Beispiel #4
0
        public void UpdateDataSet(string updateStatement, string deleteStatement, DataSet ds, bool queryTypeUpdateCommand, bool queryTypeDeleteCommand, params object[] allParams)
        {
            SqlConnection  conn = null;
            SqlCommand     updCmd;
            SqlCommand     delCmd;
            SqlCommand     cmd = null;
            SqlDataAdapter da;

            try
            {
                conn               = SqlUtil.CreateConnection(ConnectionString);
                updCmd             = SqlUtil.CreateCommand(conn);
                updCmd.CommandText = updateStatement;
                if (queryTypeUpdateCommand)
                {
                    updCmd.CommandType = CommandType.Text;
                }
                else
                {
                    updCmd.CommandType = CommandType.StoredProcedure;
                }

                delCmd             = SqlUtil.CreateCommand(conn);
                delCmd.CommandText = deleteStatement;
                if (queryTypeDeleteCommand)
                {
                    delCmd.CommandType = CommandType.Text;
                }
                else
                {
                    delCmd.CommandType = CommandType.StoredProcedure;
                }

                if (allParams != null)
                {
                    for (int iCount = 0; iCount < allParams.Length; iCount++)
                    {
                        if (iCount == 0)
                        {
                            cmd = updCmd;
                        }
                        else if (iCount == 1)
                        {
                            cmd = delCmd;
                        }
                        object obj = allParams[iCount];
                        if (obj == null)
                        {
                            continue;
                        }

                        if (obj is IList)
                        {
                            foreach (DBParameter db in (IList)obj)
                            {
                                if (db.ParamValue == null)
                                {
                                    AddDBParamNoValue(cmd, (DBParameter)db);
                                }
                                else
                                {
                                    AddDBParam(cmd, (DBParameter)db);
                                }
                            }
                        }
                        else
                        if (((DBParameter)obj).ParamValue == null)
                        {
                            AddDBParamNoValue(cmd, (DBParameter)obj);
                        }
                        else
                        {
                            AddDBParam(cmd, (DBParameter)obj);
                        }
                    }
                }

                da = new SqlDataAdapter();
                da.UpdateCommand = updCmd;
                da.InsertCommand = updCmd;
                da.DeleteCommand = delCmd;
                //da.UpdateBatchSize = 10;
                da.Update(ds);
            }
            finally
            {
                SqlUtil.ReleaseConnection(conn);
            }
        }