| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 
 |  
using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
using System.Data;
 
namespace Transfert1
{
    class Program
    {
        static void Main(string[] args)
        {
            string connectionStringSource = "Data Source=SRVSQL2;Initial Catalog=ATE_Results;Persist Security Info=True;User ID=yy;Password=xxx";
            string connectionStringDestination = "Data Source=SRVSQL2\\DEV;Initial Catalog=ATE_Results;Persist Security Info=True;User ID=yy;Password=xxx";
 
            SqlConnection connectionSource = new SqlConnection(connectionStringSource);
            SqlConnection connectionDestination = new SqlConnection(connectionStringDestination);
 
            using (connectionSource)
            {
                SqlCommand command = new SqlCommand("SELECT * from dbo.Result;",connectionSource);
                connectionSource.Open();
 
                SqlDataReader reader = command.ExecuteReader();
 
 
 
                string str = @"insert into dbo.Result(idsResult,idsATE,strConfiguration,strWorkOrder,strTestStage,lngLapPass,lngLapFail,
                                                    lngCycleCount,lngCycleFail,lngCycleFailCriteria,lngCyclePass,lngCyclePassCriteria,
                                                    lngCyclePassBegin,
                                                    lngCyclePassBeginCriteria,lngCyclePassEnd,lngCyclePassEndCriteria) 
                                                    VALUES(@a, @b, @c, @d, @e, @f, @g, @h, @i, @j, @k, @l, @m, @n,@o, @p)";
 
 
                connectionDestination.Open();
                SqlCommand sqlCommand = new SqlCommand(str, connectionDestination);
 
                sqlCommand.Parameters.Add("@a", SqlDbType.Int);
                sqlCommand.Parameters.Add("@b", SqlDbType.Int);
                sqlCommand.Parameters.Add("@c", SqlDbType.NVarChar,255);
                sqlCommand.Parameters.Add("@d", SqlDbType.NVarChar,50);
                sqlCommand.Parameters.Add("@e", SqlDbType.NVarChar,50);
                sqlCommand.Parameters.Add("@f", SqlDbType.Int);
                sqlCommand.Parameters.Add("@g", SqlDbType.Int);
                sqlCommand.Parameters.Add("@h", SqlDbType.Int);
                sqlCommand.Parameters.Add("@i", SqlDbType.Int);
                sqlCommand.Parameters.Add("@j", SqlDbType.Int);
                sqlCommand.Parameters.Add("@k", SqlDbType.Int);
                sqlCommand.Parameters.Add("@l", SqlDbType.Int);
                sqlCommand.Parameters.Add("@m", SqlDbType.Int);
                sqlCommand.Parameters.Add("@n", SqlDbType.Int);
                sqlCommand.Parameters.Add("@o", SqlDbType.Int);
                sqlCommand.Parameters.Add("@p", SqlDbType.Int);
 
                try
                {
                    sqlCommand.Prepare();
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.ToString());
                }
 
 
                // Call Read before accessing data.
                while (reader.Read())
                {
 
                    sqlCommand.Parameters["@a"].Value = Convert.ToInt16(reader[0]);
                    sqlCommand.Parameters["@b"].Value = Convert.ToInt16(reader[1]);
                    sqlCommand.Parameters["@c"].Value = reader[2];
                    sqlCommand.Parameters["@d"].Value = reader[3];
                    sqlCommand.Parameters["@e"].Value = reader[4];
                    sqlCommand.Parameters["@f"].Value = Convert.ToInt16(reader[5]);
                    sqlCommand.Parameters["@g"].Value = Convert.ToInt16(reader[6]);
                    if (reader[7] != System.DBNull.Value)
                    {
                        sqlCommand.Parameters["@h"].Value = Convert.ToInt16(reader[7]);
                    }
                    else
                    {
                        sqlCommand.Parameters["@h"].Value = null;
                    }
 
                    sqlCommand.Parameters["@i"].Value = Convert.ToInt16(reader[8]);
                    sqlCommand.Parameters["@j"].Value = Convert.ToInt16(reader[9]);
                    sqlCommand.Parameters["@k"].Value = Convert.ToInt16(reader[10]);
                    sqlCommand.Parameters["@l"].Value = Convert.ToInt16(reader[11]);
                    sqlCommand.Parameters["@m"].Value = Convert.ToInt16(reader[12]);
                    sqlCommand.Parameters["@n"].Value = Convert.ToInt16(reader[13]);
                    sqlCommand.Parameters["@o"].Value = Convert.ToInt16(reader[14]);
                    sqlCommand.Parameters["@p"].Value = Convert.ToInt16(reader[15]);
 
                    try
                    {
                        sqlCommand.ExecuteNonQuery();
                    }
                    catch (SqlException sqlEx)
                    {
                        Console.WriteLine(sqlEx.ToString());
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.ToString());
                    }
 
                }
 
 
                reader.Close();
            } | 
Partager