本文介绍了为什么只有第一条记录添加到另一个表中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨朋友们,



我正在尝试将每条记录从名为Emp_master的访问表转移到LeaveMastr。执行代码后,发现只有第一条记录添加到LeaveMaster,最长为Emp_master。我的代码如下:



我的尝试:



  Sub  DataTrans()
Dbconnection.Open()

Dim StrArr( 2 ) As 字符串

MasterReader = MasterCmd.ExecuteReader()

尝试
while MasterReader.Read()
StrArr( 0 )=(MasterReader( CPF_No .ToString))
StrArr( 1 )=(MasterReader( Name .ToString))
StrArr( 2 )=(MasterReader( 名称.ToString))

尝试
LvMasterCmd.CommandText = INSERT INTO LeaveMaster&
(CPF_No,Name,Designation,MNT,YR,LeaveStatus)&
VALUES(@ CPF_No,@ Name,@ Designation,@ MNT,@ YR,@ LeaveStatus);

LvMasterCmd.Parameters.AddWithValue( @ CPF_No,StrArr( 0 ))
LvMasterCmd.Parameters.AddWithValue( @ Name,StrArr( 1 ))
LvMasterCmd.Parameters.AddWithValue( @ Designation,StrArr( 2 ))

LvMasterCmd.Parameters.AddWithValue( @ MNT,CmbMonth.Text)
LvMasterCmd.Parameters.AddWithValue( @ YR,CmbYear.Text)
LvMasterCmd.Parameters.AddWithValue( @ LeaveStatus, N)

LvMasterCmd.ExecuteNonQuery()

Catch ex As 异常
结束 尝试

结束

Catch ex As 异常
MessageBox.Show(ex.Message)
结束 尝试
Dbconnection.Close()
结束 Sub
解决方案



Hi Friends,

I am trying to transfer each record from access table named Emp_master to LeaveMastr. After execution of code it is found that only first record added to LeaveMaster up to the length of Emp_master. My codes ara as follows:

What I have tried:

Sub DataTrans()
   Dbconnection.Open()

   Dim StrArr(2) As String 

   MasterReader = MasterCmd.ExecuteReader()

   Try
      While MasterReader.Read()
         StrArr(0) = (MasterReader("CPF_No".ToString))
         StrArr(1) = (MasterReader("Name".ToString))
         StrArr(2) = (MasterReader("Designation".ToString))

         Try
            LvMasterCmd.CommandText = "INSERT INTO LeaveMaster" &
                                         "(CPF_No, Name, Designation,  MNT, YR, LeaveStatus)" &
                                         "VALUES ( @CPF_No, @Name, @Designation,  @MNT, @YR, @LeaveStatus) ;"

            LvMasterCmd.Parameters.AddWithValue("@CPF_No", StrArr(0))
            LvMasterCmd.Parameters.AddWithValue("@Name", StrArr(1))
            LvMasterCmd.Parameters.AddWithValue("@Designation", StrArr(2))

            LvMasterCmd.Parameters.AddWithValue("@MNT", CmbMonth.Text)
            LvMasterCmd.Parameters.AddWithValue("@YR", CmbYear.Text)
            LvMasterCmd.Parameters.AddWithValue("@LeaveStatus", "N")

            LvMasterCmd.ExecuteNonQuery()

         Catch ex As Exception
         End Try

      End While

   Catch ex As Exception
      MessageBox.Show(ex.Message)
   End Try
   Dbconnection.Close()
End Sub
解决方案



这篇关于为什么只有第一条记录添加到另一个表中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-14 22:20