Question
Do not worry about the config file imports which are in the first few lines, I'm using INI file for that Sub LaborTrxTransfer() Dim normac
Do not worry about the config file imports which are in the first few lines, I'm using INI file for that
Sub LaborTrxTransfer()
Dim normac As String = ConfigurationManager.AppSettings(\"normac\")
Dim mesDev As String = ConfigurationManager.AppSettings(\"mesDev\") Dim newServer As String = ConfigurationManager.AppSettings(\"newServer\")
Dim maxNormID As String = ConfigurationManager.AppSettings(\"maxNormID\") Dim normCount As SqlDataReader
Dim normacNextID As Integer
Try Using cn As New SqlConnection(mesDev), cmd As New SqlCommand(maxNormID, cn) cn.Open() normCount = cmd.ExecuteReader() While normCount.Read() normacNextID = normCount.Item(0) FileIO.WriteLog(normCount.Item(0)) End While FileIO.WriteLog(\"Maximum ID of Normac labor/footage : \" & normacNextID) normCount.Close() cn.Close() End Using Catch ex As Exception FileIO.WriteLog(\"There was an error getting the maximum source ID for Normac records from ALL_LABOR_RECORDS table : \" & ex.Message) End Try
Dim lastNormID As Integer Dim sql1 As String = \"SELECT ID, RTRIM(trx_date), RTRIM(work_order), RTRIM(department), RTRIM(work_center), RTRIM(operation_no), RTRIM(operator), RTRIM(total_labor_hours), RTRIM(feet_produced), RTRIM(item_no), RTRIM(lot_no), RTRIM(default_bin) FROM NOR_LABOR WHERE ID > \" & normacNextID & \" ORDER BY ID;\"
Dim sql2 As String = \"INSERT INTO ALL_LABOR_DETAILS VALUES (@p0, @p26, @p27, @p1, @p2, @p3, @p4, @p5, @p6, @p7, @p8, @p9, @p10, @p11, @p12, @p13, @p14, @p15, @p16, @p17, @p18, @p19, @p20, @p21, @p22, @p23, @p24, @p25);\"
Dim dt As New DataTable
Try Using cn As New SqlConnection(normac), cmd As New SqlCommand(sql1, cn), da As New SqlDataAdapter(cmd)
da.Fill(dt) End Using
Using cn As New SqlConnection(mesDev), cmd As New SqlCommand(sql2, cn)
cmd.Parameters.Add(\"@p0\", SqlDbType.Int) cmd.Parameters.Add(\"@p26\", SqlDbType.NChar).Value = \"NORMAC\" cmd.Parameters.Add(\"@p27\", SqlDbType.NChar).Value = \"Copied\" cmd.Parameters.Add(\"@p1\", SqlDbType.SmallDateTime) cmd.Parameters.Add(\"@p2\", SqlDbType.NChar) cmd.Parameters.Add(\"@p3\", SqlDbType.NChar) cmd.Parameters.Add(\"@p4\", SqlDbType.NChar) cmd.Parameters.Add(\"@p5\", SqlDbType.SmallInt) cmd.Parameters.Add(\"@p6\", SqlDbType.SmallInt) cmd.Parameters.Add(\"@p7\", SqlDbType.Decimal) cmd.Parameters.Add(\"@p8\", SqlDbType.Decimal) cmd.Parameters.Add(\"@p9\", SqlDbType.NChar) cmd.Parameters.Add(\"@p10\", SqlDbType.Char) cmd.Parameters.Add(\"@p11\", SqlDbType.NChar) cmd.Parameters.Add(\"@p12\", SqlDbType.NChar).Value = \"\" cmd.Parameters.Add(\"@p13\", SqlDbType.NChar).Value = DBNull.Value cmd.Parameters.Add(\"@p14\", SqlDbType.NChar).Value = DBNull.Value cmd.Parameters.Add(\"@p15\", SqlDbType.Decimal).Value = DBNull.Value cmd.Parameters.Add(\"@p16\", SqlDbType.NChar).Value = DBNull.Value cmd.Parameters.Add(\"@p17\", SqlDbType.NChar).Value = DBNull.Value cmd.Parameters.Add(\"@p18\", SqlDbType.NChar).Value = DBNull.Value cmd.Parameters.Add(\"@p19\", SqlDbType.Text).Value = DBNull.Value cmd.Parameters.Add(\"@p20\", SqlDbType.NChar).Value = DBNull.Value cmd.Parameters.Add(\"@p21\", SqlDbType.Int).Value = DBNull.Value cmd.Parameters.Add(\"@p22\", SqlDbType.VarChar).Value = DBNull.Value cmd.Parameters.Add(\"@p23\", SqlDbType.VarChar).Value = DBNull.Value cmd.Parameters.Add(\"@p24\", SqlDbType.VarChar).Value = DBNull.Value cmd.Parameters.Add(\"@p25\", SqlDbType.VarChar).Value = DBNull.Value
cn.Open() For Each row As DataRow In dt.Rows For i As Integer = 0 To 11 cmd.Parameters($\"@p{i}\").Value = row(i) lastNormID = row(0) 'Added to keep the last copied ID up to date and make sure it copies from that point up Next i
cmd.ExecuteNonQuery() FileIO.WriteLog($\"Most Recent Normac ID {row(0)}\") Next row End Using Catch ex As Exception FileIO.WriteLog(\"Exception caught in Normac : \" & ex.Message) End Try
End Sub
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started