error after upgrade vb to vb.net - vb.net

i upgrade my project to vb.net by using visual basic. i get a error when run the crystal report.
Call ReportConnection(CInspAuditList, "A")
CInspAuditList.ReportFileName = My.Application.Info.DirectoryPath & "\A.rpt"
Call SubReportConnection(CInspAuditList, "A")
CInspAuditList.set_ParameterFields(0, temp1)
CInspAuditList.set_ParameterFields(1, temp2)
CInspAuditList.set_ParameterFields(2, temp3)
CInspAuditList.set_ParameterFields(3, temp4)
CInspAuditList.Action = 1
my connection is
Public Function ReportConnection(ByRef CrystalReport1 As Object, ByRef dsnname As String) As Boolean
Try
CrystalReport1.Connect = "dsn=" & dsnname & ";UID=" & gstrID & ";PWD=" & gstrPassword & ";DSQ="
Catch ex As Exception
MsgBox(ex.ToString)
End
End Try
End Function
Public Function SubReportConnection(ByRef CrystalReport1 As Object, ByRef dsnname As String) As Object
Dim NReport As Short
With CrystalReport1
NReport = .GetNSubreports
Do While NReport > 0
.SubreportToChange = .GetNthSubreportName(NReport - 1)
.Connect = "dsn=" & dsnname & ";UID=" & gstrID & ";PWD=" & gstrPassword & ";DSQ="
.SubreportToChange = ""
NReport = NReport - 1
Loop
End With
End Function
i get error Exception from HRESULT: 0x800A501B at CInspAuditList.Action = 1
may i know how to fix the error???

Related

how to use serial port in a service application environment constantly listening for data

Ive written a service application that listens to a port for any communication that may come through, our lab will run a certain test which will send serial data down every couple hours or so. the service is runs picks up the data fine for a few hours and then mysteriously stops. the system eventlog says the service terminated unexpectedly. and in the application event log it has a more descriptive .NET error,
Application: BondTestService.exe Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.ObjectDisposedException at
System.Runtime.InteropServices.SafeHandle.DangerousAddRef(Boolean
ByRef) at
System.StubHelpers.StubHelpers.SafeHandleAddRef(System.Runtime.InteropServices.SafeHandle,
Boolean ByRef) at
Microsoft.Win32.UnsafeNativeMethods.GetOverlappedResult(Microsoft.Win32.SafeHandles.SafeFileHandle,
System.Threading.NativeOverlapped*, Int32 ByRef, Boolean) at
System.IO.Ports.SerialStream+EventLoopRunner.WaitForCommEvent() at
System.Threading.ThreadHelper.ThreadStart_Context(System.Object) at
System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext,
System.Threading.ContextCallback, System.Object, Boolean) at
System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext,
System.Threading.ContextCallback, System.Object, Boolean) at
System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext,
System.Threading.ContextCallback, System.Object) at
System.Threading.ThreadHelper.ThreadStart()
i was reading how services behave and how serial ports behave, so correct me if im wrong if the there is a 2 hour gap or so inbetween tests, the service will assume that its not running and stop itself?
I also read after reading the buffer from the serial port i append to a string builder object like below and do what i need to the string, then what happens to the serial port does it just stay open waiting for next value or do i have to close it and reopen it in order to refresh it?
Not sure how to handle this as it needs to be open waiting for the lab tester to send his data at any given time.
Imports System
Imports System.Data.SqlClient
Imports System.IO.Ports
Imports System.Net.Mime
Imports Microsoft.Win32
Imports System.IO
Imports System.Text.RegularExpressions
Imports BondTestService.PI
Imports PCA.Core.Configuration
Public Class Bond
Dim WithEvents serialPort As New IO.Ports.SerialPort
Public Delegate Sub myDelegate()
Public RawString As New System.Text.StringBuilder
Public value As String
Public BondTest As Integer = 10
#Region "Commport Traffic and Configuration Validations"
Public Sub StartListening()
If serialPort.IsOpen Then
serialPort.Close()
ErrorLog2(Now.ToString & "Port Closed because StartListening method started over")
End If
Try
With serialPort
.PortName = Registry.LocalMachine.OpenSubKey("SOFTWARE\Wow6432Node\AUTOLABDEVICESERVICE\bondtest", True).GetValue("commport")
.BaudRate = CInt(Registry.LocalMachine.OpenSubKey("SOFTWARE\Wow6432Node\AUTOLABDEVICESERVICE\bondtest", True).GetValue("baudrate"))
If Registry.LocalMachine.OpenSubKey("SOFTWARE\Wow6432Node\AUTOLABDEVICESERVICE\bondtest", True).GetValue("parity") = 0 Then
.Parity = Parity.None
End If
If Registry.LocalMachine.OpenSubKey("SOFTWARE\Wow6432Node\AUTOLABDEVICESERVICE\bondtest", True).GetValue("stopbits") = 1 Then
.StopBits = StopBits.One
End If
.DataBits = CInt(Registry.LocalMachine.OpenSubKey("SOFTWARE\Wow6432Node\AUTOLABDEVICESERVICE\bondtest", True).GetValue("bytesize"))
.Handshake = Handshake.None
If Registry.LocalMachine.OpenSubKey("SOFTWARE\Wow6432Node\AUTOLABDEVICESERVICE\bondtest", True).GetValue("RtsControl") = 1 Then
.RtsEnable = True
Else
.RtsEnable = False
End If
End With
serialPort.Open()
'debug
'ErrorLog2("Listening to COM 19, SerialPort has been Opened")
Catch ex As Exception
ErrorLog2(Now.ToString & ex.tostring)
End Try
End Sub
Public Function Filelocator() As String
' Dim filePath As String = IO.Path.Combine(Application.StartupPath, "bondtest.bat")
Dim filePath As String = IO.Path.Combine("C:\Program Files (x86)\PIPC\Interfaces\Lab", "BondTest.bat")
'Dim reader As New System.IO.StreamReader(filePath)
Dim LineNumber = 4
Using file As New StreamReader(filePath)
' Skip all preceding lines: '
For i As Integer = 1 To LineNumber - 1
If file.ReadLine() Is Nothing Then
ErrorLog2("LineNumber")
End If
Next
' Attempt to read the line you're interested in: '
Dim line As String = file.ReadLine()
If line Is Nothing Then
ErrorLog2("LineNumber")
End If
Return line
End Using
End Function
Private Sub serialPort_DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort.DataReceived
Try
If GetBondInterfaceStatus = 1 Then
UPdateVariable()
Else
exit Sub
End If
Catch ex As Exception
Errorlog2(Ex.Tostring)
End Try
End Sub
#End Region
#Region "String Handling"
Public Sub UPdateVariable()
With RawString
.Append(serialPort.ReadLine())
End With
try
ErrorLog2(now.ToString & RawString.ToString)
InsertTestDataDEBUG(GetRecordID, BondTest, BondTestType.ToUpper.ToString, GetBondPosition(), StringParser(RawString.ToString()), RawString.tostring)
InsertTestData(GetRecordID, BondTest, BondTestType.ToUpper.ToString, GetBondPosition(), StringParser(RawString.ToString()))
RawString.Clear()
Catch ex As Exception
ErrorLog2(ex.ToString())
End Try
End Sub
Public Function StringParser(RawString As String)As Double ()
Dim Moisture = RawString
Dim pattern As String = "[0-9],"
Dim regex As New Regex(pattern)
Dim Counter As Integer = 0
Dim dblValues(1) As Double
Dim values As String() = Moisture.Split(New Char() {" "c})
for i = 0 to values.Count - 1
if regex.IsMatch(values(i)) Then
dblValues(Counter) = CDbl(values(i).Substring(0,1))
Counter = Counter + 1
Elseif values(i) = "" Then
continue for
else
if Double.TryParse(values(i), dblValues(Counter)) Then
Counter = Counter + 1
End If
End If
Next
Return dblValues
End Function
#End Region
#Region "SQL Statements"
Private Sub InsertTestData(RecordID As Integer, BondTest As Integer, TestType As String, TestPos As Integer, dataArray() As Double)
Dim InsertQuery As String = ""
Dim conn As New BondSQLConnection("PaperTests")
' Dim TestPos = StartingTestPos + (CInt(dataArray(0)) - 1)
conn("#RecordID") = RecordID
conn("#Test") = BondTest
conn("#TestType") = TestType
conn("#TestPos") = TestPos
conn("#TestData") = dataArray(1)
conn("#TestDateTime") = now.tostring
InsertQuery = "INSERT INTO PaperTests.dbo.PaperTestValues(ReelRecordID, Test, TestLocation, TestPosition, TestValue, TestTimeStamp) VALUES (#RecordID, #Test, #TestType, #TestPos, #TestData, #TestDateTime)"
Try
conn.ExecuteNonQuery(InsertQuery)
IncrementTestPosition
Catch ex As Exception
ErrorLog2(ex.ToString())
End Try
End Sub
Private Sub InsertTestDataDEBUG(RecordID As Integer, BondTest As Integer, TestType As String, TestPos As Integer, dataArray() As Double, rawString As String)
Dim InsertQuery As String = ""
Dim conn As New BondSQLConnection("PaperTests")
conn("#RecordID") = RecordID
conn("#Test") = BondTest
conn("#TestType") = TestType
conn("#TestPos") = TestPos
conn("#TestData") = dataArray(1)
conn("#RawString") = rawString
conn("#TestDateTime") = now.tostring
InsertQuery = "INSERT INTO PaperTests.dbo.InterfaceTesting(ReelRecordID, Test, TestLocation, TestPosition, TestValue, TestTimeStamp, RawValue) VALUES (#RecordID, #Test, #TestType, #TestPos, #TestData, #TestDateTime, #RawString)"
Try
conn.ExecuteNonQuery(InsertQuery)
Catch ex As Exception
ErrorLog2(ex.ToString())
End Try
End Sub
Private Sub IncrementTestPosition()
Dim tempPosition As Integer = GetBondPosition()
Dim FrontOriginalMax = 5
Dim CenterOriginalMax = 15
Dim BackOriginalMax = 25
Dim FrontRetestOrWinderMax = 10
Dim CenterRetestOrWinderMax = 20
Dim BackRetestOrWinderMax = 30
If tempPosition = FrontOriginalMax Then
tempPosition = 11
else if tempPosition = CenterOriginalMax Then
tempPosition = 21
else if tempPosition = BackOriginalMax Then
tempPosition = 1
Else If tempPosition = FrontRetestOrWinderMax then
tempPosition = 1
Else If tempPosition = CenterRetestOrWinderMax then
tempPosition = 1
Else If tempPosition = BackRetestOrWinderMax then
tempPosition = 1
else
tempPosition = tempPosition + 1
End If
SetBondPosition(tempPosition.tostring)
End Sub
#End Region
#Region "Get PiValues"
Private Function GetRecordID() As Int64
Dim RecordID As Int32 = 0
Try
Dim piserver As New PIServer("valpi", "piadmin", "fatb0y",True)
RecordID = piserver.GetCurrentValue("PAPERLAB:PaperLabReelSelected")
Catch ex As Exception
ErrorLog2(ex.ToString())
End Try
Return RecordID
End Function
Private Function GetBondPosition() As Int64
Dim BondPos As Int32 = 0
Try
Dim piserver As New PIServer("valpi", "piadmin", "fatb0y",True)
BondPos = CInt(piserver.GetCurrentValue("PAPERLAB:SBOND.POS"))
Catch ex As Exception
ErrorLog2(ex.ToString())
End Try
Return BondPos
End Function
Private Sub SetBondPosition(pos As String)
Try
Dim piserver As New PIServer("valpi", "piadmin", "fatb0y",True)
piserver.WriteValue("PAPERLAB:SBOND.POS", pos)
Catch ex As Exception
ErrorLog2(ex.ToString())
End Try
End Sub
Private Function BondTestType() As String
Dim TestType As String = ""
Try
Dim piserver As New PIServer("valpi", "piadmin", "fatb0y",True)
TestType = piserver.GetCurrentValue("M1:BOND.TYPE")
Catch ex As Exception
ErrorLog2(ex.ToString())
End Try
Return TestType
End Function
Private Function BondReelLoc() As String
Dim ReelLoc As String = ""
Try
Dim piserver As New PIServer("valpi", "piadmin", "fatb0y",True)
ReelLoc = piserver.GetCurrentValue("M1:BOND.ReelLoc")
Catch ex As Exception
ErrorLog2(ex.ToString())
End Try
Return ReelLoc
End Function
Private Function GetBondInterfaceStatus() As Integer
Dim Status As Integer = 0
Try
Dim piserver As New PIServer("valpi", "piadmin", "fatb0y",True)
Status = CInt(piserver.GetCurrentValue("PAPERLAB:BOND_INTERFACE.S"))
Catch ex As Exception
ErrorLog2(ex.ToString())
End Try
Return Status
End Function
#End Region
#Region "Debug"
Private Sub ErrorLog(RecordID As Int32, BondTest As Integer, ReelLoc As String, TestType As String, StartingTestPos As Integer, dataArray() As Double)
Dim SavePath As String = "C:\Program Files (x86)\PIPC\Interfaces\Lab"
Dim NameOfFile As String = "BondTest Debug File"
Dim TestPos = StartingTestPos + (CInt(dataArray(0)) - 1)
If System.IO.File.Exists(SavePath & "\" & NameOfFile & ".txt") Then
Using sw As StreamWriter = New StreamWriter(SavePath & "\" & NameOfFile & ".txt", True)
' For i = 0 To dataArray.Count -1
sw.WriteLine(" ")
sw.WriteLine(RecordID & " " & BondTest & " " & ReelLoc & " " & TestType & " " & TestPos & " " & dataArray(1).ToString)
' TestPos = TestPos + 1
' Next
End Using
else
File.Create(SavePath & "\" & NameOfFile & ".txt").Dispose()
Using sw As StreamWriter = File.CreateText(SavePath & "\" & NameOfFile & ".txt")
'For i = 0 To dataArray.Count -1
sw.WriteLine(" ")
sw.WriteLine(RecordID & " " & BondTest & " " & ReelLoc & " " & TestType & " " & TestPos & " " & dataArray(1).ToString)
' TestPos = TestPos + 1
'Next
End Using
End If
End Sub
Private Sub ErrorLog2(dataArray as string)
Dim SavePath As String = "C:\Program Files (x86)\PIPC\Interfaces\Lab"
Dim NameOfFile As String = "BondTest Debug File"
' Dim TestPos = StartingTestPos
If System.IO.File.Exists(SavePath & "\" & NameOfFile & ".txt") Then
Using sw As StreamWriter = New StreamWriter(SavePath & "\" & NameOfFile & ".txt", True)
sw.WriteLine(" ")
sw.WriteLine(dataArray)
End Using
else
File.Create(SavePath & "\" & NameOfFile & ".txt").Dispose()
Using sw As StreamWriter = File.CreateText(SavePath & "\" & NameOfFile & ".txt")
sw.WriteLine(" ")
sw.WriteLine(dataArray)
End Using
End If
End Sub
#End Region
This is a screenshot of the errors:
Thanks in advance
Normally, after opening the serial port in .NET it stays opened for arbitrary time. I've written several .NET applications were serial ports are used for months or years without app or computer restart and they work well.
According to the exception info you posted it looks like that serial port has been disposed. There are several possible reasons.
Using bad driver or HW, that disconnects your serial port. I've been using many USB-to-RS232 converters and some of them had bad drivers so sometimes ports were randomly disconnected and ObjectDisposedException was thrown. In earlier Windows editions (XP) the OS even 'blue-screened'. Here is more info about such situation where ObjectDisposedException is thrown.
This is a known problem with SerialPort. Device removal causes an uncatchable exception in a background thread it uses (WaitForCommEvent). The only solutions are to not use SerialPort or create a .config file that puts unhandled exception trapping mode back to .NET 1.1 behavior.
The USB cable of your RS232 converter is manually disconnected. If you do this, most drivers normally disconnect all handles to your serial port and .NET throws ObjectDisposedException.
Also check your power management settings on your USB port if USB-to-RS232 converter is used. Try to uncheck this option on USB device to which converter is connected.
SW bug in your code.
It's always advisable (especially if converter used) to try more types of converters just to be sure there is no problem in HW device/driver.
Update: So as Timmy was saying the connection was getting disposed by garbage collection. so i declared the object as a shared variable in the class
Shared Dim WithEvents serialPort as IO.Ports.SerialPort
and in the OnStart method i initiated it as a new Serial port and rocked on. has not throw any errors since garbage collection wont disposed of it. Hope this helps somebody having a similar issue.

Getting BC31019 excepetion while compiling vb.net at runtime on Windows 10

we are generating a mass of documents very dynamically. Therefore we concatenate source code and build a dll at runtime. This is running since windows XP.
Now we are in tests of windows 10 and it fails compiling this dll with the error "BC31019: Unable to write to output file 'C:\Users[name]AppData\Local\Temp\xyz.dll': The specified image file did not contain a resource section"
For testing purposes we remove all generated source code and replace it by a rudimental class with only one function (throwing an exception with specified text) and no referenced assemblies.
This is also running on all machines except windows 10. Same error.
Can anybody guess why?
This is the rudimental method
Public Sub Compile()
Dim lSourceCode = "Namespace DynamicOutput" & vbCrLf &
" Public Class Template" & vbCrLf &
" Sub New()" & vbCrLf &
" End Sub" & vbCrLf &
" Public Sub Generate(ByVal spoolJob As Object, ByVal print As Object)" & vbCrLf &
" Throw New System.Exception(""Generate reached"")" & vbCrLf &
" End Sub" & vbCrLf &
"" & vbCrLf &
" End Class" & vbCrLf &
"End Namespace"
Dim lParams As CodeDom.Compiler.CompilerParameters = New CodeDom.Compiler.CompilerParameters
lParams.CompilerOptions = "/target:library /rootnamespace:CompanyName /d:TRACE=TRUE /optimize "
lParams.IncludeDebugInformation = True
lParams.GenerateExecutable = False
lParams.TreatWarningsAsErrors = False
lParams.GenerateInMemory = True
Dim lProviderOptions As New Dictionary(Of String, String) From {{"CompilerVersion", "v4.0"}}
Dim lResult As CodeDom.Compiler.CompilerResults = Nothing
Using provider As New VBCodeProvider(lProviderOptions)
lResult = provider.CompileAssemblyFromSource(lParams, lSourceCode)
End Using
' ... check for errors
Dim lInstance As Object = lResult.CompiledAssembly.CreateInstance("CompanyName.DynamicOutput.Template")
lInstance.GetType.GetMethod("Generate").Invoke(lInstance, New Object() {Me.SpoolJob, Me.Print})
End Sub

For-loop doesn't complete all iterations

I have problem with this - I try to send broadcast SMS using AT Commands in my system. After that the SMS content will be stored in my database. My store content SMS function works well. I can store all my SMS content that I send, but the send function just sends message to my first data on my datagridview.
Please help me to deal with this - I posted my code below
Private Sub ButtonKirim_Click(sender As Object, e As EventArgs) Handles ButtonKirim.Click
Dim noPel As String
Dim isiPesan As String = ""
Dim tgl As Date = Now.Date
Dim strReplace(2) As String
Dim strIsi(2) As String
Dim tagBulan As String = "<bulan>"
Dim tagtagihan As String = "<tagihan>"
Dim tagLokasi As String = "<lokasi>"
Dim pesanKirim As String = ""
My.Settings.SettingPesan = RichTextBoxPesan.Text
My.Settings.Save()
'Label4.Text = isiPesan
For pelanggan As Integer = 0 To DataGridViewKirimPesan.RowCount - 1
'mengirim pesan/send message
noPel = DataGridViewKirimPesan.Rows(pelanggan).Cells(3).Value()
strReplace(0) = tagBulan
strReplace(1) = tagtagihan
strReplace(2) = tagLokasi
strIsi(0) = DataGridViewKirimPesan.Rows(pelanggan).Cells(4).Value
strIsi(1) = DataGridViewKirimPesan.Rows(pelanggan).Cells(5).Value
strIsi(2) = DataGridViewKirimPesan.Rows(pelanggan).Cells(6).Value
isiPesan = RichTextBoxPesan.Text
For i As Integer = LBound(strReplace) To UBound(strReplace)
isiPesan = isiPesan.Replace(strReplace(i), strIsi(i))
Next
SendMessage(noPel, isiPesan)
''menyimpan pesan keluar ke sms_terkirim/this query store my content SMS to table
Dim sqlSmsKeluar As String = "INSERT INTO sms_terkirim (`tgl_sms`,`id_pelanggan`, `isi_sms`) VALUES ( NOW()," & DataGridViewKirimPesan.Rows(pelanggan).Cells(0).Value & " , '" & isiPesan & "');"
cudMethod(sqlSmsKeluar)
MsgBox(sqlSmsKeluar)
'ProgressBarKirimPesan.Increment(1)
Next
'MsgBox("Pesan Sukses Terkirim")
' Catch ex As Exception
' MsgBox("Pesan Gagal Terkirim" + ex.Message)
'End Try
' End If
End Sub
and this code is AT Command to send message
Public Sub SendMessage(ByVal NomorPelanggan As String, ByVal IsiPesan As String)
If SerialModem.IsOpen() Then
With SerialModem
.Write("AT" & vbCrLf)
Threading.Thread.Sleep(100)
.Write("AT+CMGF=1" & vbCrLf)
Threading.Thread.Sleep(100)
.Write("AT+CMGS=" & Chr(34) & NomorPelanggan & Chr(34) & vbCrLf)
Threading.Thread.Sleep(100)
.Write(IsiPesan & vbCrLf & Chr(26))
Threading.Thread.Sleep(100)
End With
Else
MsgBox("Modem Belum Tersambung")
End If
End Sub

Long query won't work

Im new to vb and im working on a monitoring system with a long query
If frm_MonitoringReg.txtIDnumber.Text = String.Empty Or frm_MonitoringReg.txtAddress.Text = String.Empty Or frm_MonitoringReg.txtBirthPlace.Text = String.Empty Or frm_MonitoringReg.txtFirstName.Text = String.Empty Or frm_MonitoringReg.txtIDnumber.Text = String.Empty Or frm_MonitoringReg.txtLastName.Text = String.Empty Or frm_MonitoringReg.txtMiddleName.Text = String.Empty Or frm_MonitoringReg.cmbCivilStatus.SelectedIndex = 0 Or frm_MonitoringReg.cmbGender.SelectedIndex = 0 Then
MsgBox("Must Fill All Fields")
Else
Dim AccountDS, PersonDS As New DataSet
'Dim Command As New SqlCommand(SQLCon)
'Command.Open()
Dim cmdSelectPersonInfo As New SqlCommand("SELECT * FROM [186].[dbo].personInfo WHERE pIDnumber = #pIDnumber", Connection)
cmdSelectPersonInfo.CommandType = CommandType.Text
cmdSelectPersonInfo.Parameters.AddWithValue("#pIDnumber", frm_MonitoringReg.txtIDnumber.Text)
Dim dAdapterPerson As New SqlDataAdapter(cmdSelectPersonInfo)
dAdapterPerson.Fill(PersonDS)
If PersonDS.Tables(0).Rows.Count >= 1 Then
MsgBox("Person Information is already created")
Else
Dim cmdAddPersonInfo As New SqlCommand("INSERT INTO [186].[dbo].[personInfo] (pIDnumber, pLname, pFname, pMname, pAddress, " & _
"pGender, pBirthday, pBirthPlace, pCivilStatus, DeletedFlag, createBy, createDate,pWorking " & _
"pOccupation,pStudying,pTSchool ,pHEducation,pDisability,pYr,pPrecinct,pYrBahay,pKPaninirahan " & _
"pKPKanino,pKPUpa,pLTinitirhan,pLTukuyin,pKBahay,pKtukuyin,pMBahay,pMTukuyin,pMeralco,pMaynilad " & _
"pTelepono,pBKita,pGPamilya,pKapitbahay,pPalikuran,pPagluluto,pPTukuyin,pTubig,pTTukuyin,pIlaw " & _
"pITukuyin,pLTelevision,pLVideoke,pLSports,pLMusical,pLReading,pLMalling,pLHiking,pHAso " & _
"pHPusa,pHManok,pHBaboy,pHIba,pHBilang,pSKotse,pSVan,pSJeepney,pSTricycle,pSIba,pSIba,pKRadio,pKAudio,pKKaraoke " & _
"pKPiano,pKCellphone,pKTV,pKVideoP,pKCam,pKWood,pKKerosene,pKLPG,pKGas,pKEStove,pKERange,pKMicrowave " & _
"pKRef,pKFreezer,pKWashing,pKHeated,pKAircon,pKEFan,pKETank,pKEHeater,pKComputer,pKLaptop,pKSystem,pKFlatI) " & _
"VALUES (#IDnumber, #Lname, #Fname, #Mname, #Address, #Gender, #bDay, #bPlace, #CivilStat, #deletedFlag, #createBy, #createDate " & _
"#pWorking,#pOccupation,#pStudying,#pTSchool,#pHEducation,#pDisability,#pYr,#pPrecinct,#pYrBahay,#pKPaninirahan " & _
"#pKPKanino,#pKPUpa,#pLTinitirhan,#pLTukuyin,#pKBahay,#pKtukuyin,#pMBahay,#pMTukuyin,#pMeralco,#pMaynilad " & _
"#pTelepono,#pBKita,#pGPamilya,#pKapitbahay,#pPalikuran,#pPagluluto,#pPTukuyin,#pTubig,#pTTukuyin,#pIlaw " & _
"#pITukuyin,#pLTelevision,#pLVideoke,#pLSports,#pLMusical,#pLReading,#pLMalling,#pLHiking,#pHAso " & _
"#pHPusa,#pHManok,#pHBaboy,#pHIba,#pHBilang,#pSKotse,#pSVan,#pSJeepney,#pSTricycle,#pSIba,#pSIba,#pKRadio,#pKAudio,#pKKaraoke " & _
"#pKPiano,#pKCellphone,#pKTV,#pKVideoP,#pKCam,#pKWood,#pKKerosene,#pKLPG,#pKGas,#pKEStove,#pKERange,#pKMicrowave " & _
"#pKRef,#pKFreezer,#pKWashing,#pKHeated,#pKAircon,#pKEFan,#pKETank,#pKEHeater,#pKComputer,#pKLaptop,#pKSystem,#pKFlatI)", Connection)
cmdAddPersonInfo.CommandType = CommandType.Text
cmdAddPersonInfo.Parameters.AddWithValue("#IDnumber", frm_MonitoringReg.txtIDnumber.Text)
cmdAddPersonInfo.Parameters.AddWithValue("#Lname", frm_MonitoringReg.txtLastName.Text)
cmdAddPersonInfo.Parameters.AddWithValue("#Fname", frm_MonitoringReg.txtFirstName.Text)
cmdAddPersonInfo.Parameters.AddWithValue("#Mname", frm_MonitoringReg.txtMiddleName.Text)
cmdAddPersonInfo.Parameters.AddWithValue("#Address", frm_MonitoringReg.txtAddress.Text)
cmdAddPersonInfo.Parameters.AddWithValue("#Gender", frm_MonitoringReg.cmbGender.Text)
cmdAddPersonInfo.Parameters.AddWithValue("#bDay", frm_MonitoringReg.dtpBirthDay.Text)
cmdAddPersonInfo.Parameters.AddWithValue("#bPlace", frm_MonitoringReg.txtBirthPlace.Text)
cmdAddPersonInfo.Parameters.AddWithValue("#CivilStat", frm_MonitoringReg.cmbCivilStatus.Text)
cmdAddPersonInfo.Parameters.AddWithValue("#deletedFlag", 0)
cmdAddPersonInfo.Parameters.AddWithValue("#createBy", LoginForm.txtUsername.Text)
cmdAddPersonInfo.Parameters.AddWithValue("#createDate", Now.Date.ToString)
cmdAddPersonInfo.Parameters.AddWithValue("#pWorking", frm_MonitoringReg.chckWorking.CheckState)
cmdAddPersonInfo.Parameters.AddWithValue("#pOccupation", frm_MonitoringReg.txtOccupation)
cmdAddPersonInfo.Parameters.AddWithValue("#pStudying", frm_MonitoringReg.chckStudying.CheckState)
cmdAddPersonInfo.Parameters.AddWithValue("#pTSchool", frm_MonitoringReg.cmboTypeofSchool.Text)
cmdAddPersonInfo.Parameters.AddWithValue("#pHEducation", frm_MonitoringReg.cmboHighestEduc.Text)
cmdAddPersonInfo.Parameters.AddWithValue("#pDisability", frm_MonitoringReg.chckDisablity.CheckState)
cmdAddPersonInfo.Parameters.AddWithValue("#pYr", frm_MonitoringReg.txtYrofStay)
cmdAddPersonInfo.Parameters.AddWithValue("#pPrecinct", frm_MonitoringReg.txtPrecintNo)
cmdAddPersonInfo.Parameters.AddWithValue("#pYrBahay", frm_MonitoringReg.txttyr)
cmdAddPersonInfo.Parameters.AddWithValue("#pKPaninirahan", frm_MonitoringReg.cmboKatayuan.Text)
cmdAddPersonInfo.Parameters.AddWithValue("#pKPKanino", frm_MonitoringReg.txtKanino)
cmdAddPersonInfo.Parameters.AddWithValue("#pKPUpa", frm_MonitoringReg.txtUpa)
cmdAddPersonInfo.Parameters.AddWithValue("#pLTinitirhan", frm_MonitoringReg.cmboLote.Text)
cmdAddPersonInfo.Parameters.AddWithValue("#pLTukuyin", frm_MonitoringReg.txtlTukuyin)
cmdAddPersonInfo.Parameters.AddWithValue("#pKBahay", frm_MonitoringReg.cmboBahay.Text)
cmdAddPersonInfo.Parameters.AddWithValue("#pKtukuyin", frm_MonitoringReg.txtbTukuyin)
cmdAddPersonInfo.Parameters.AddWithValue("#pMBahay", frm_MonitoringReg.cmbomBahay.Text)
cmdAddPersonInfo.Parameters.AddWithValue("#pMTukuyin", frm_MonitoringReg.txtmTukuyin)
cmdAddPersonInfo.Parameters.AddWithValue("#pMeralco", frm_MonitoringReg.chckMeralco.CheckState)
cmdAddPersonInfo.Parameters.AddWithValue("#pMaynilad", frm_MonitoringReg.chckMaynilad.CheckState)
cmdAddPersonInfo.Parameters.AddWithValue("#pTelepono", frm_MonitoringReg.chckTelepono.CheckState)
cmdAddPersonInfo.Parameters.AddWithValue("#pBKita", frm_MonitoringReg.txtKita)
cmdAddPersonInfo.Parameters.AddWithValue("#pGPamilya", frm_MonitoringReg.txtGastos)
cmdAddPersonInfo.Parameters.AddWithValue("#pKapitbahay", frm_MonitoringReg.txtKapitbahay)
cmdAddPersonInfo.Parameters.AddWithValue("#pPalikuran", frm_MonitoringReg.cmboPalikuran.Text)
cmdAddPersonInfo.Parameters.AddWithValue("#pPagluluto", frm_MonitoringReg.cmboPagluluto.Text)
cmdAddPersonInfo.Parameters.AddWithValue("#pPTukuyin", frm_MonitoringReg.txtpTukuyin)
cmdAddPersonInfo.Parameters.AddWithValue("#pTubig", frm_MonitoringReg.cmboTubig.Text)
cmdAddPersonInfo.Parameters.AddWithValue("#pTTukuyin", frm_MonitoringReg.txttTukuyin.Text)
cmdAddPersonInfo.Parameters.AddWithValue("#pIlaw", frm_MonitoringReg.cmboIlaw.Text)
cmdAddPersonInfo.Parameters.AddWithValue("#pITukuyin", frm_MonitoringReg.txtiTukuyin.Text)
cmdAddPersonInfo.Parameters.AddWithValue("#pLTelevision", chckTelevision.CheckState)
cmdAddPersonInfo.Parameters.AddWithValue("#pLVideoke", chckVideoke.CheckState)
cmdAddPersonInfo.Parameters.AddWithValue("#pLSports", chckSports.CheckState)
cmdAddPersonInfo.Parameters.AddWithValue("#pLMusical", chckMusicalInstruments.CheckState)
cmdAddPersonInfo.Parameters.AddWithValue("#pLReading", chckReading.CheckState)
cmdAddPersonInfo.Parameters.AddWithValue("#pLMalling", chckMalling.CheckState)
cmdAddPersonInfo.Parameters.AddWithValue("#pLHiking", chckHiking.CheckState)
cmdAddPersonInfo.Parameters.AddWithValue("#pLReading", chckReading.CheckState)
cmdAddPersonInfo.Parameters.AddWithValue("#pHAso", txtAso.Text)
cmdAddPersonInfo.Parameters.AddWithValue("#pHPusa", txtPusa.Text)
cmdAddPersonInfo.Parameters.AddWithValue("#pHManok", txtManok.Text)
cmdAddPersonInfo.Parameters.AddWithValue("#pHBaboy", txtBaboy.Text)
cmdAddPersonInfo.Parameters.AddWithValue("#pHIba", TxtHIba.Text)
cmdAddPersonInfo.Parameters.AddWithValue("#pHBilang", txtHBilang.Text)
cmdAddPersonInfo.Parameters.AddWithValue("#pSKotse", txtkotse.Text)
cmdAddPersonInfo.Parameters.AddWithValue("#pSVan", txtVan.Text)
cmdAddPersonInfo.Parameters.AddWithValue("#pSJeepney", txtJeepney.Text)
cmdAddPersonInfo.Parameters.AddWithValue("#pSTricycle", txtTricycle.Text)
cmdAddPersonInfo.Parameters.AddWithValue("#pSIba", txtSIba.Text)
cmdAddPersonInfo.Parameters.AddWithValue("#pSBilang", txtSBilang.Text)
cmdAddPersonInfo.Parameters.AddWithValue("#pKRadio", txtRadio.Text)
cmdAddPersonInfo.Parameters.AddWithValue("#pKAudio", txtSystem.Text)
cmdAddPersonInfo.Parameters.AddWithValue("#pKKaraoke", txtKaraoke.Text)
cmdAddPersonInfo.Parameters.AddWithValue("#pKPiano", txtKeyboard.Text)
cmdAddPersonInfo.Parameters.AddWithValue("#pKCellphone", txtCp.Text)
cmdAddPersonInfo.Parameters.AddWithValue("#pKTV", txtTV.Text)
cmdAddPersonInfo.Parameters.AddWithValue("#pKVideoP", txtVideoP.Text)
cmdAddPersonInfo.Parameters.AddWithValue("#pKCam", txtCamcorder.Text)
cmdAddPersonInfo.Parameters.AddWithValue("#pKWood", txtWood.Text)
cmdAddPersonInfo.Parameters.AddWithValue("#pKKerosene", txtKerosene.Text)
cmdAddPersonInfo.Parameters.AddWithValue("#pKLPG", txtStove.Text)
cmdAddPersonInfo.Parameters.AddWithValue("#pKGas", txtGas.Text)
cmdAddPersonInfo.Parameters.AddWithValue("#pKEStove", txtElectric.Text)
cmdAddPersonInfo.Parameters.AddWithValue("#pKERange", txtElectricCooking.Text)
cmdAddPersonInfo.Parameters.AddWithValue("#pKMicrowave", txtOven.Text)
cmdAddPersonInfo.Parameters.AddWithValue("#pKRef", txtRef.Text)
cmdAddPersonInfo.Parameters.AddWithValue("#pKFreezer", txtFreezer.Text)
cmdAddPersonInfo.Parameters.AddWithValue("#pKWashing", txtWashing.Text)
cmdAddPersonInfo.Parameters.AddWithValue("#pKHeated", txtDryer.Text)
cmdAddPersonInfo.Parameters.AddWithValue("#pKAircon", txtAirCon.Text)
cmdAddPersonInfo.Parameters.AddWithValue("#pKEFan", txtFan.Text)
cmdAddPersonInfo.Parameters.AddWithValue("#pKETank", txtTank.Text)
cmdAddPersonInfo.Parameters.AddWithValue("#pKEHeater", txtHeater.Text)
cmdAddPersonInfo.Parameters.AddWithValue("#pKCompute", txtComputer.Text)
cmdAddPersonInfo.Parameters.AddWithValue("#pKLaptop", txtLaptop.Text)
cmdAddPersonInfo.Parameters.AddWithValue("#pKSystem", txtGameSystem.Text)
cmdAddPersonInfo.Parameters.AddWithValue("#pKFlatI", txtFlatiron.Text)
Dim dAdapter As New SqlDataAdapter(cmdAddPersonInfo)
dAdapter.Fill(AccountDS)
MsgBox("Information Successfuly Added")
frm_MonitoringReg.Close()
Me.Close()
Monitoring.Show()
End If
End If
But when I try to save it I get an error in line
Dim dAdapter As New SqlDataAdapter(cmdAddPersonInfo)
dAdapter.Fill(AccountDS)
The error says "No mapping exists from object type System.Windows.Forms.TextBox to a known managed provider native type.". The first time I tried to input the program it successfully input but only until the table "createby" so I try to find why it stops there but I failed to find it and this error pops out of nowhere. I don't know what to do anymore.
You really should think about doing a few things differently.
But anyway: Your problem is because your are missing the .Text for a number of these statements. You need to add that specifically for these lines:
cmdAddPersonInfo.Parameters.AddWithValue("#pYr", frm_MonitoringReg.txtYrofStay)
cmdAddPersonInfo.Parameters.AddWithValue("#pPrecinct", frm_MonitoringReg.txtPrecintNo)
cmdAddPersonInfo.Parameters.AddWithValue("#pYrBahay", frm_MonitoringReg.txttyr)
cmdAddPersonInfo.Parameters.AddWithValue("#pKPaninirahan", frm_MonitoringReg.cmboKatayuan.Text)
cmdAddPersonInfo.Parameters.AddWithValue("#pKPKanino", frm_MonitoringReg.txtKanino)
cmdAddPersonInfo.Parameters.AddWithValue("#pKPUpa", frm_MonitoringReg.txtUpa)
cmdAddPersonInfo.Parameters.AddWithValue("#pMTukuyin", frm_MonitoringReg.txtmTukuyin)
cmdAddPersonInfo.Parameters.AddWithValue("#pBKita", frm_MonitoringReg.txtKita)
cmdAddPersonInfo.Parameters.AddWithValue("#pGPamilya", frm_MonitoringReg.txtGastos)
cmdAddPersonInfo.Parameters.AddWithValue("#pKapitbahay", frm_MonitoringReg.txtKapitbahay)
cmdAddPersonInfo.Parameters.AddWithValue("#pPTukuyin", frm_MonitoringReg.txtpTukuyin)
And possibly some more that I have missed.

Error: Index and length must refer to a location within the string

Im getting the following exception on vb.net. I have trouble solving this error:
Error 5: Index and length must refer to a location within the string.Parameter name: length.
here is my code :
Private Sub attemptedNumbersNew2(ByVal date_start As DateTime, ByVal date_end As DateTime, ByVal port As String, ByVal team As String)
Dim con As New ADODB.Connection
Dim recordS As New ADODB.Recordset
Dim sql As String = "some query...."
Try
con.Open(connectStringA)
recordS.Open(sql, con)
If recordS.EOF Then
Else
Do While Not recordS.EOF
Dim temp As String
If name4number.Contains(lastAttempted) Then
temp = name4number.Item(lastAttempted)
Else
temp = lastAttempted
End If
If attemptedNames.Equals("NONE") Or attemptedNames.Equals("") Then
attemptedNames = temp
ElseIf Not temp.Equals("") Then
attemptedNames = attemptedNames & " - " & temp
End If
If agentsHashOffered.Contains(temp & "_" & team) Then
agentsHashOffered.Item(temp & "_" & team) = agentsHashOffered.Item(temp & "_" & team) + 1
Else
agentsHashOffered.Add(temp & "_" & team, 1)
End If
If recordS.Fields(2).Value >= oldDate Then
If answeringNumber.Equals("NONE") Then
answeringNumber = recordS.Fields(4).Value
If answeringNumber.Substring(0, 1).Equals("9") Then
answeringNumber = answeringNumber.Substring(1, 10)
End If
callDuration = -1
End If
disconnectionTime = recordS.Fields(3).Value
Else
End If
If attempted.Equals("NONE") Then
attempted = recordS.Fields(4).Value
If attempted.Substring(0, 1).Equals("9") Then
attempted = attempted.Substring(1, 10)
End If
attemptedCount = attemptedCount + 1
lastAttempted = attempted
Else
temp = recordS.Fields(4).Value
If temp.Substring(0, 1).Equals("9") Then
temp = temp.Substring(1, 10)
End If
attempted = attempted & " - " & temp
attemptedCount = attemptedCount + 1
lastAttempted = temp
End If
recordS.MoveNext()
Loop
End If
con.Close()
con = Nothing
recordS = Nothing
Catch ex As Exception
MsgBox("Error #" & Err.Number & ": " & Err.Description)
End Try
End Sub
It was working fine the other day, but suddenly I started getting this error.
any helps are welcome
THANK YOU in Advance