Long query won't work - sql

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.

Related

Datagridview - Insert an image into a cell in a specific row

I have a vb.net project where I have a DataGridView (called "dgvRevisiones") to record information about vehicle damage records.
Through an SFTP that I have previously configured, I have the photos of each damage record, my program downloads them in a temporary folder and that works perfect.
The problem is when I need to insert each image of each record in the corresponding cell.
Currently I have a code that only inserts the last image it collects and repeats it throughout the column.
Here I leave my code:
Public Sub ExtraerImagenRegistrosDaño()
Dim img As Image
Dim imagecol As New DataGridViewImageColumn
imagecol.ImageLayout = DataGridViewImageCellLayout.Zoom
FormPrincipal.dgvRevisiones.Columns.Insert(0, imagecol)
Dim rutaTmp = Application.StartupPath & "/tmp"
If (Not System.IO.Directory.Exists(rutaTmp)) Then
System.IO.Directory.CreateDirectory(rutaTmp)
End If
For rowIndex = 0 To FormPrincipal.dgvRevisiones.RowCount - 1
Dim idreg = FormPrincipal.dgvRevisiones.Rows(rowIndex).Cells("idreg").Value.ToString
Dim descripcion = FormPrincipal.dgvRevisiones.Rows(rowIndex).Cells("descripcion").Value.ToString
ConexionBD.conectar()
Dim recoleccionidins As New DataTable
comandoquery = "SELECT idins FROM registro_dano WHERE descripcion='" & descripcion & "' AND idreg='" & idreg & "'"
comando.Connection = ConexionBD.conexion
comando.CommandText = comandoquery
recoleccionidins.Load(comando.ExecuteReader)
Dim idinsExtraido = recoleccionidins.Rows(0).Item(0).ToString().Trim()
ConexionBD.cerrar()
Dim sessionOptions As New SessionOptions
With sessionOptions
.Protocol = Protocol.Sftp
.HostName = "HOST"
.UserName = "USER"
.Password = "PASSWORD"
.GiveUpSecurityAndAcceptAnySshHostKey = True
End With
Using session As New Session
session.Open(sessionOptions)
Try
session.GetFiles("/home/sislota/database-registros-dano/Registro-" & idinsExtraido & "-" & idreg & ".png", rutaTmp & "\Registro-" & idinsExtraido & "-" & idreg & ".png").Check()
Catch ex As Exception
End Try
End Using
And here start the issue:
Try
img = Image.FromFile(rutaTmp & "\Registro-" & idinsExtraido & "-" & idreg & ".png")
Catch ex As Exception
End Try
imagecol.Image = img
Next
End Sub

vb.net WPF application combobox not waiting for user to choose

I have a wpf vb.net application (written in VS 2019 community) containing two website searches. The first search is a string search and that either produces one result, which I then load into the second search, or it produces more than one result, which I load into a combobox to let the user choose. My problem is getting the application to stop and allow the user to choose from the combobox. I have implemented a workaround that uses a modal form containing a combobox and this allows the user to choose from the combobox and supply the value to the second search. I have been advised to use the 'change' event for the combobox but there isn't one available, I have also been advised to use the selectedindexchanged but the control doesn't let the dropdown list occur to select anything. I have also tried using various forms of addhandler (commented out in the code below).
' Build the 'Search API' URL.
Dim uri = New Uri("https://api.themoviedb.org/3/search/tv?" _
& "api_key=" & TMDBAPIKey _
& "&language=en-US" _
& "&query=" & sLvl1NodeName _
& "&page=1" _
& "&first_air_date_year=" & sFirstXmitYear)
' Retrieve the IMDB ID with an API Search function using the series title
Try
Dim Site = New WebClient()
Answer = Site.DownloadString(uri)
Catch ex As NullReferenceException
Dim messagetext As String = "The 'Search API' from GetDetails popup failed with : " _
& ex.Message & " for: Title=" & sLvl1NodeName
Me.txtErrorMessageBox.Text = messagetext
Exit Sub
End Try
' Deserialise the answer
Dim JsonElem As TMDBtitle = JsonConvert.DeserializeObject(Of TMDBtitle)(Answer)
' If the websearch finds only one result this is the TV series we want, if more than
' one result is found load the results into a combobox and get the user to choose.
If JsonElem.results.Length = 1 Then
TVSeriesID = JsonElem.results(0).id
Else
Me.cmbChooseSeries.BeginUpdate()
Me.lblChooseSeries.Text = Me.lblChooseSeries.Text & "( " & JsonElem.results.Length & " )"
Me.cmbChooseSeries.Items.Clear()
For Each titleresult In JsonElem.results
ComboSeriesChoice = titleresult.name & " | " &
titleresult.id & " | " &
titleresult.first_air_date & " | " &
titleresult.overview
Me.cmbChooseSeries.Items.Add(ComboSeriesChoice)
Next
cmbChooseSeries.DroppedDown = True
Me.cmbChooseSeries.EndUpdate()
If cmbChooseSeries.SelectedIndex <> -1 Then
Dim var1 = cmbChooseSeries.SelectedText
Else
Threading.Thread.Sleep(3000)
End If
'AddHandler cmbChooseSeries.MouseDoubleClick,
'Sub()
'Threading.Thread.Sleep(3000)
'End Sub
TVSeriesID = cmbChooseSeries.SelectedItem
End If
' Build the 'TV Search API' call URL.
Dim urix = New Uri("https://api.themoviedb.org/3/tv/" _
& TVSeriesID & "?" _
& "api_key=" & TMDBAPIKey _
& "&language=en-US")
Try
Dim site = New WebClient()
Answer = site.DownloadString(urix) ' download the JSON from the server.
Catch ex As NullReferenceException
Dim MessageText As String = "The 'TV Search API' from GetDetails popup failed with : " _
& ex.Message & " for: Title=" & sLvl1NodeName & " ID=" & popupid
Me.txtErrorMessageBox.Text = MessageText
Exit Sub
End Try
Dim jsonelemx = JsonConvert.DeserializeObject(Of TVResult)(Answer)
lstDetailItems(0) = "Name"
lstDetailItems(1) = jsonelemx.name
lstDetailItems(2) = (String.Empty)
Dim DelItems = New ListViewItem(lstDetailItems)
Me.lstSeriesDetails.Items.Add(DelItems)
lstDetailItems(0) = "Status"
lstDetailItems(1) = jsonelemx.status
lstDetailItems(2) = (String.Empty)
DelItems = New ListViewItem(lstDetailItems)
Me.lstSeriesDetails.Items.Add(DelItems)
lstDetailItems(0) = "Episode run time"
lstDetailItems(1) = Convert.ToString(jsonelemx.episode_run_time(0))
lstDetailItems(2) = (String.Empty)
DelItems = New ListViewItem(lstDetailItems)
Me.lstSeriesDetails.Items.Add(DelItems)

First-chance exception at 0x761EC42D in foo.exe: Microsoft C++ exception: int at memory location 0x003ED1EC

Dim ColNames(7) As String
Dim Values(7) As Object
Dim now As DateTime = DateTime.Now()
ColNames(0) = "Int1"
ColNames(1) = "Int2"
ColNames(2) = "String1"
ColNames(3) = "String2"
ColNames(4) = "String3"
ColNames(5) = "String4"
ColNames(6) = "String5"
ColNames(7) = "String6"
Values(0) = intVar1
Values(1) = intVar2
Values(2) = strVar1
Values(3) = strVar2
Values(4) = strVar3
Values(5) = strVar4
Values(6) = strVar5
Values(7) = strVar6
Dim goodToInsert As Boolean = True
For i As Integer = 0 To 7
If Values(i) = Nothing OrElse Len(Values(i)) = 0 Then
goodToInsert = False
End If
Next
If goodToInsert Then
accessDatabase.InsertIntoTable("MyTable", ColNames, Values)
End If
This part of the code handles gathering data to insert into my access database.
Public Sub InsertIntoTable(ByRef TableName As String, ByRef ColumnName() As String, ByRef KeyValue() As Object)
'ColumnName and KeyValue need to have the same number of elements
'be careful when attemping to insert a value into the PrimaryKey Column as it may be of a type that cannot but manually changed
'INSERT NEW DATA INTO A TABLE
' INSERT INTO {tablename} ([{columnname1}], [{columnname2}], [{columnname3}], ...) VALUES ('{string}', {number}, {boolean}, ...), oledbconnection
Dim ColumnString As String = vbNullString
Dim KeyString As String = vbNullString
For i As Integer = 0 To ColumnName.GetUpperBound(0)
'build the column names part of the string
If i <> ColumnName.GetUpperBound(0) Then
ColumnString = ColumnString & "[" & ColumnName(i) & "], "
Else
ColumnString = ColumnString & "[" & ColumnName(i) & "]"
End If
'build the values part of the string
Dim TempValue As String = vbNullString
If KeyValue(i) <> Nothing Then
If KeyValue(i).GetType.ToString = "System.String" Then
TempValue = "'" & KeyValue(i) & "'"
Else
TempValue = KeyValue(i)
End If
If i <> KeyValue.GetUpperBound(0) Then
KeyString = KeyString & vbNullString & TempValue & ", "
Else
KeyString &= TempValue
End If
Else
Debug.Print("Nothing")
If i <> KeyValue.GetUpperBound(0) Then
KeyString &= ", "
End If
End If
Next
Dim con As New OleDbConnection
Dim da As New OleDbDataAdapter
Dim sql As New OleDbCommand
con.ConnectionString = Connection()
con.Open()
Dim commandText As String = "INSERT INTO " & TableName & " (" & ColumnString & ") VALUES (" & KeyString & ")"
Try
sql.Connection = con
sql.CommandText = commandText
da.InsertCommand = sql
da.InsertCommand.ExecuteNonQuery()
Catch ex As Exception
Debug.Print(ex.ToString)
End Try
con.Close()
End Sub
This is the InsertIntoTable function.
The function runs properly and inserts data into my table correctly, but in my debug output I keep noticing this error on every call to da.InsertCommand.ExecuteNonQuery():
First-chance exception at 0x761EC42D in 3024 Card Sorter.exe: Microsoft C++ exception: int at memory location 0x003ED1EC.
First-chance exception at 0x761EC42D in 3024 Card Sorter.exe: Microsoft C++ exception: int at memory location 0x003ED1EC.
I was able to use the Visual Studio debugger to narrow it down to ExecuteNonQuery() being where it occurs, but I'm having trouble understanding what it means, and how to go about resolving it. I've attempted changing my intVars to Strings with no luck to resolving the exception, and I'm also extremely curious why this isn't being caught by my Try...Catch.

Email a table using VB.Net

I need to send an email with a table that has variable values in each cell. I can do this using any method (html via email, an excel/word table, etc.). The only hitch is due to the restrictions of the Emailer program and System.Net.Mail import, it has to be a string.
Here's what I have so far:
Imports DelayEmailer.DelayTrackerWs
Imports System.Configuration
Public Class DelayEmailer
Public Shared Sub Main()
Dim ws As New DelayTrackerWs.DelayUploader
Dim delays As DelayTrackerWs.Delay()
Dim emailer As New Emailer()
Dim delaystring As String
delays = ws.SearchDelaysDate(DelayTrackerWs.AreaEnum.QT, DelayTrackerWs.UnitEnum.QT, Now.AddDays(-1), Now)
delaystring = "Delays" & vbNewLine
delaystring &= "Facilty Start Time Status Category Reason Comment"
For i = 0 To delays.Length - 1
delaystring &= vbNewLine & delays(i).Facility & " "
delaystring &= FormatDateTime(delays(i).DelayStartDateTime, DateFormat.ShortDate) & " "
delaystring &= FormatDateTime(delays(i).DelayStartDateTime, DateFormat.ShortTime) & " "
'delaystring &= delays(i).DelayDuration & " "
delaystring &= delays(i).Status & " "
delaystring &= delays(i).CategoryCode & " "
delaystring &= delays(i).ReasonCode & " "
delaystring &= delays(i).Comment
Next
emailer.Send(ConfigurationManager.AppSettings("EmailList"), "delays", delaystring)
End Sub
As you can see, I currently have just a bunch of concatenated strings that line up if the values of each delays(i) are the same. The other problem is that this needs to be easily viewable via mobile devices and with the strings, it wraps and gets really unreadable. A table here should fix this.
You can send html email from .NET using MailMessage and SmtpClient classes, create an email template as string and set MailMessage's IsBodyHtml property to true:
Dim strHeader As String = "<table><tbody>"
Dim strFooter As String = "</tbody></table>"
Dim sbContent As New StringBuilder()
For i As Integer = 1 To rows
sbContent.Append("<tr>")
For j As Integer = 1 To cols
sbContent.Append(String.Format("<td>{0}</td>", YOUR_TD_VALUE_STRING))
Next j
sbContent.Append("</tr>");
Next i
Dim emailTemplate As String = strHeader & sbContent.ToString() & strFooter
...

error after upgrade vb to 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???