March 18, 2014 at 11:52 pm
Hi
I am trying to insert data from an SQL Server Table into and SQL CE Table with a VB Project.
I am receiving an IndexoutofRangeException was unhandled An{0} with {1} '{2}' is not contained by this {3}. on the sqlcmd.Parameters(0).Value = myreader.GetValue(0) line
Any help would be appreciated or if a better method could be suggested
Code
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim sqlCEconn As New SqlCeConnection("Data Source =C:\PayrollDB.sdf")
Try
sqlCEconn.Open()
Dim strConnString As String = "Data Source=Server;Initial Catalog=SP_Reconciliation; Integrated Security=SSPI"
Dim sqlCon = New SqlConnection(strConnString)
sqlCon.Open()
Dim cmd As SqlCommand = New SqlCommand("select EmployerCode, personnel_no from CurrentEmployees", sqlCon)
Dim myreader As SqlDataReader = cmd.ExecuteReader
Dim sqlcmd As SqlCeCommand = New SqlCeCommand("insert into StaffLookup (EmpCode, Empid) values(@Emp, @per)", sqlCEconn)
While myreader.Read()
sqlcmd.Parameters(0).Value = myreader.GetValue(0)
sqlcmd.Parameters(1).Value = myreader.GetValue(1)
sqlcmd.ExecuteNonQuery()
End While
Catch ex As SqlException
MessageBox.Show(ex.ToString)
End Try
End Sub
Viewing 0 posts
You must be logged in to reply to this topic. Login to reply