Exemple #1
0
 public void AddSQLParameters(SqlCommand sqlcmd, SqlParameter[] sqlParam)
 {
     for (int i = 0; i < sqlParam.GetLength(0); i++)
         {
             sqlcmd.Parameters.Add(sqlParam[i]);
         }
 }
        public void AddSQLParameters(SqlCommand sqlcmd, SqlParameter[] sqlParam)
        {
            for (int i = 0; i < sqlParam.GetLength(0); i++)
            {
                if (sqlParam[i] == null)
                    break;

                sqlcmd.Parameters.Add(sqlParam[i]);
                sqlcmd.Parameters[i].Direction = sqlParam[i].Direction;

                if (sqlParam[i].Value != "")
                    Framework.Utilities.DebugLogging.Log("SQL PARAM " + i + " : " + sqlParam[i] + " " + sqlParam[i].Value);
            }
        }
Exemple #3
0
        private SqlParameter[] transObjToParams(string[] str, Object[] obj)
        {
            SqlParameter[] param = new SqlParameter[obj.GetLength(0)];
            for (int i = 0; i < param.GetLength(0); i++) {
                if (obj[i] is Int32) {
                    param[i] = new SqlParameter("?" + str[i], SqlDbType.Int);
                    param[i].Value = Convert.ToInt32(obj[i]);
                }
                else if (obj[i] is Double) {
                    param[i] = new SqlParameter("?" + str[i], SqlDbType.Float);
                    param[i].Value = Convert.ToDouble(obj[i]);
                }
                else {
                    try {
                        Convert.ToDateTime(obj[i]);
                        param[i] = new SqlParameter("?" + str[i], SqlDbType.DateTime);
                        param[i].Value = Convert.ToString(obj[i]);
                    }
                    catch {
                        param[i] = new SqlParameter("?" + str[i], SqlDbType.VarChar);
                        param[i].Value = Convert.ToString(obj[i]);
                    }
                }

            }
            return param;
        }
Exemple #4
0
    // Needs reader to be positioned on the first row
    private static void CopyReader(SqlDataReader reader, SqlConnection outCon,
        string outTable, SqlParameter[] paramList)
    {
        using (SqlCommand outCmd = outCon.CreateCommand())
        try {
            System.Text.StringBuilder insertCmdStr =
                new System.Text.StringBuilder();

            insertCmdStr.AppendFormat("INSERT INTO {0} VALUES (", outTable);

            for (int i = 0; i < paramList.GetLength(0); i++) {
                if (i > 0)
                    insertCmdStr.Append(", ");

                insertCmdStr.AppendFormat("@col{0}", i);
                outCmd.Parameters.Add(paramList[i]);
            }

            insertCmdStr.Append(")");

            outCmd.CommandText = insertCmdStr.ToString();

            // If this throws, the most likely culprit is one (or more) of the
            // SqlParameters being generated incorrectly in GenerateSchema()
            outCmd.Prepare();

            do {
                for (int i = 0; i < paramList.GetLength(0); i++) {
                    paramList[i].SqlValue = reader.GetSqlValue(i);
                }
                outCmd.ExecuteNonQuery();

                if (sendDebugInfo)
                    SqlContext.Pipe.Send(string.Format("Record sent to {0}",
                            outTable));
            } while (reader.Read());

            outCmd.Parameters.Clear();
        } catch (SqlException e) {
            throw new System.Exception(
                string.Format("Could not send data to {0}", outTable), e);
        }
    }