Open multiples csv files in the folder using vb.net - vb.net

The following codes below should work to load all csv files data in the datagridview by why I am getting the error of the method of operation is not implemented. Here are the codes. Do u guys have any solution
Imports System.IO
Imports System.Text
Public Class ReadBo
Public Shared Function ReadFile(ByVal FilePath As String) As DataTable
Try
Dim pathway As String() = Directory.GetFiles(FilePath)
Dim dt As New DataTable
dt.Columns.Add("File name")
For item As Integer = 0 To pathway.Length - 1
Dim files As New FileInfo(pathway(item))
Dim dr As DataRow = dt.NewRow()
Dim Lines As String() = File.ReadAllLines(files.ToString())
Dim Fields As String()
Fields = Lines(0).Split(New Char() {","})
Dim Cols As Integer = Fields.GetLength(0)
If item = 0 Then
For i As Integer = 1 To Cols
dt.Columns.Add("Col" & i, GetType(String))
Next
End If
For index As Integer = 0 To Lines.GetLength(0) - 1
Fields = Lines(index).Split(New Char() {","})
dr = dt.NewRow()
dr(0) = files.Name
For f = 1 To Cols
dr(f) = Fields(f - 1)
Next
dt.Rows.Add(dr)
Next
Next
Return dt
Catch ex As Exception
MessageBox.Show("Error is " + ex.ToString())
End Try
End Function
End Class
Imports Task2.ReadBo
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Try
DataGridView1.AutoGenerateColumns = True
Dim initialPath As String = "C:\Users\ng.yipeng\Desktop\Task2"
FolderBrowserDialog1.SelectedPath = initialPath
If FolderBrowserDialog1.ShowDialog() = DialogResult.OK Then
TextBox1.Text = FolderBrowserDialog1.SelectedPath.ToString()
Me.DataGridView1.DataSource = ReadFile(TextBox1.Text)
End If
Catch ex As Exception
MsgBox("Error: " & ex.Message)
End Try
End Sub
Private Function ReadFile(p1 As String) As Object
Throw New NotImplementedException
End Function
End Class

Related

How to compare two rows from different excel's into one new excel in vb.net?

I am starting to program in vb.net and I am making a program that takes values ​​from excel columns of 2 files and shows results in a generated excel.
so the first excel has this columns: delivery number, contentID, packages, volume. the second excel has this columns:SPS Number, folder number, contentID, packages, volume.
the excel that i have to generato has this columns:SPS number,folder number, delivery number, contentID,packages, volume. The excel that i have to generate with the program uses contentID as the main identificator, and it has ti compare the packages and volume if the ContentID is the same.
so far i have this in a funtions file:
Module Funciones
'VARIABLES REMATE'
Public ENTREGA As New List(Of String)
Public PAQUETE As New List(Of String)
Public CONTENEDOR As New List(Of String)
Public VOLUMEN As New List(Of String)
'VARIABLES PLANILLA'
Public NSPS As New List(Of String)
Public NPLANILLA As New List(Of String)
Public PAQUETE2 As New List(Of String)
Public IDCONTENEDOR As New List(Of String)
Public VOLUMEN2 As New List(Of String)
Public Sub INICIALIZAR_PLANILLA(ByRef HOJAUSUARIOS As OfficeOpenXml.ExcelWorksheet)
Try
HOJAUSUARIOS.Cells("A1").Value = "N° SPS"
HOJAUSUARIOS.Cells("B1").Value = "N° PLANILLA"
HOJAUSUARIOS.Cells("C1").Value = "ENTREGA"
HOJAUSUARIOS.Cells("D1").Value = "CONTENEDOR"
HOJAUSUARIOS.Cells("E1").Value = "PAQUETES"
HOJAUSUARIOS.Cells("F1").Value = "VOLUMEN"
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
Public Function seleccionardirectorio(ByVal filtro As String) As String
Dim saveFileDialog1 As New SaveFileDialog()
saveFileDialog1.Filter = filtro
saveFileDialog1.Title = "Seleccione Directorio"
saveFileDialog1.ShowDialog()
Return saveFileDialog1.FileName
End Function
Function extraer_valores_remate(ByRef ruta As String) As Boolean
ExcelPackage.LicenseContext = LicenseContext.NonCommercial
Try
Dim stream = System.IO.File.OpenRead(ruta)
Dim package = New OfficeOpenXml.ExcelPackage(stream)
'// Libro
Dim Workbook = package.Workbook
'// Hojas
Dim hojas = Workbook.Worksheets
' Dim aux As Integer = 1
'While (Workbook.Worksheets.Count >= aux)
Dim hojaUsuarios = Workbook.Worksheets(Workbook.Worksheets.Item(0).ToString)
Dim indice As Integer = 2
While (indice < 2000)
'Numero entrega'
If (IsNothing(hojaUsuarios.Cells("A" & indice).Value) = False) Then
ENTREGA.Add(hojaUsuarios.Cells("A" & indice).Value)
End If
'Numero Contenedor'
If (IsNothing(hojaUsuarios.Cells("B" & indice).Value) = False) Then
CONTENEDOR.Add(hojaUsuarios.Cells("B" & indice).Value)
End If
'Paquete'
If (IsNothing(hojaUsuarios.Cells("C" & indice).Value) = False) Then
PAQUETE.Add(hojaUsuarios.Cells("C" & indice).Value)
End If
'Volumen'
If (IsNothing(hojaUsuarios.Cells("D" & indice).Value) = False) Then
VOLUMEN.Add(hojaUsuarios.Cells("D" & indice).Value)
End If
indice += 1
End While
indice += 1
Catch EX As Exception
MsgBox(EX.ToString)
Return False
End Try
Return True
End Function
Function extraer_valores_planilla(ByRef ruta As String) As Boolean
ExcelPackage.LicenseContext = LicenseContext.NonCommercial
Try
Dim stream = System.IO.File.OpenRead(ruta)
Dim package = New OfficeOpenXml.ExcelPackage(stream)
'// Libro
Dim Workbook = package.Workbook
'// Hojas
Dim hojas = Workbook.Worksheets
' While (Workbook.Worksheets.Count >= aux)
Dim hojaUsuarios = Workbook.Worksheets(Workbook.Worksheets.Item(0).ToString)
Dim indice As Integer = 2
While (indice < 5000)
'Numero entrega'
If (IsNothing(hojaUsuarios.Cells("A" & indice).Value) = False) Then
NSPS.Add(hojaUsuarios.Cells("A" & indice).Value)
End If
'Numero Contenedor'
If (IsNothing(hojaUsuarios.Cells("B" & indice).Value) = False) Then
NPLANILLA.Add(hojaUsuarios.Cells("B" & indice).Value)
End If
'Paquete'
If (IsNothing(hojaUsuarios.Cells("C" & indice).Value) = False) Then
IDCONTENEDOR.Add(hojaUsuarios.Cells("C" & indice).Value)
End If
'Volumen'
If (IsNothing(hojaUsuarios.Cells("D" & indice).Value) = False) Then
PAQUETE2.Add(hojaUsuarios.Cells("D" & indice).Value)
End If
If (IsNothing(hojaUsuarios.Cells("E" & indice).Value) = False) Then
VOLUMEN2.Add(hojaUsuarios.Cells("E" & indice).Value)
End If
indice += 1
End While
indice += 1
Catch EX As Exception
MsgBox(EX.ToString)
Return False
End Try
Return True
End Function
Public Sub LIMPIAR_VARIABLES_REMATE()
ENTREGA.Clear()
CONTENEDOR.Clear()
PAQUETE.Clear()
VOLUMEN.Clear()
End Sub
Public Sub LIMPIAR_VARIABLES_PLANILLA()
ENTREGA.Clear()
CONTENEDOR.Clear()
PAQUETE.Clear()
VOLUMEN.Clear()
End Sub
and on the main file i have this
Imports System.IO
Imports System.Text.RegularExpressions Imports OfficeOpenXml Imports OfficeOpenXml.Style
Public Class Form1 Private Sub Label1_Click(sender As Object, e As EventArgs) Handles Label1.Click
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim OFD As New OpenFileDialog
OFD.Title = "Selecciona un archivo"
OFD.Filter = "XLSX|*.xlsx"
If OFD.ShowDialog() = DialogResult.OK Then
Dim extension As String = System.IO.Path.GetExtension(OFD.FileName)
Dim nombreOriginal As String = System.IO.Path.GetFullPath(OFD.FileName)
TextBox1.Text = nombreOriginal
extraer_valores_remate(nombreOriginal)
Button4.Enabled = True
Button3.Enabled = True
Else
MsgBox("Campo Requerido", MsgBoxStyle.Exclamation, Title:="Faltan Datos")
TextBox1.Focus()
End If
End Sub
Public nombre_archivo As String = ""
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
Dim OFD As New OpenFileDialog
OFD.Title = "Selecciona un archivo"
OFD.Filter = "XLSX|*.xlsx"
If OFD.ShowDialog() = DialogResult.OK Then
Dim extension As String = System.IO.Path.GetExtension(OFD.FileName)
nombre_archivo2 = System.IO.Path.GetFileName(OFD.FileName)
Dim nombreOriginal As String = System.IO.Path.GetFullPath(OFD.FileName)
TextBox2.Text = nombreOriginal
extraer_valores_planilla(nombreOriginal)
Else
MsgBox("Campo Requerido", MsgBoxStyle.Exclamation, Title:="Faltan Datos")
TextBox2.Focus()
End If
End Sub
Public nombre_archivo2 As String = ""
'********VARIABLES EXCEL DE CARGA**********'
'Public ENTREGA As New List(Of String)
'Public IDCONTENEDOR As New List(Of String)
''Public PAQUETES As New List(Of String)
'Public VOLUMEN As New List(Of String)
'Public NSPS As New List(Of String)
'Public NPLANILLA As New List(Of String)
'Public IDCONTENERDOR2 As New List(Of String)
'' Public PAQUETES2 As New List(Of String)
'Public VOLUMEN2 As New List(Of String)
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
LIMPIAR_VARIABLES_REMATE()
TextBox1.Text = ""
MsgBox("Las variables del remate se han limpiado correctamente", MsgBoxStyle.Information, Title:="LIMPIAR")
End Sub
Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
ExcelPackage.LicenseContext = LicenseContext.NonCommercial
Dim path As String = seleccionardirectorio("Excel|.xlsx")
If (String.IsNullOrWhiteSpace(path) = False) Then
Dim excel = New ExcelPackage(New FileInfo(path))
excel.Workbook.Worksheets.Add("Hoja1")
Dim aux As Integer = 1
Dim Workbook = excel.Workbook
Dim hojas = Workbook.Worksheets
Dim hoja1 = Workbook.Worksheets("Hoja1")
'DAMOS NOMBRE A LAS COLUMNAS
INICIALIZAR_PLANILLA(hoja1)
While (aux <= CONTENEDOR.Count)
hoja1.Cells("C" & aux + 1).Value = ENTREGA.Item(aux - 1)
aux += 1
End While
aux = 1
While (aux <= IDCONTENEDOR.Count)
hoja1.Cells("A" & aux + 1).Value = NSPS.Item(aux - 1)
aux += 1
End While
aux = 1
While (aux <= IDCONTENEDOR.Count)
hoja1.Cells("B" & aux + 1).Value = NPLANILLA.Item(aux - 1)
aux += 1
End While
aux = 1
While (aux <= IDCONTENEDOR.Count)
hoja1.Cells("D" & aux + 1).Value = IDCONTENEDOR.Item(aux - 1)
aux += 1
End While
aux = 1
While (aux <= IDCONTENEDOR.Count)
hoja1.Cells("E" & aux + 1).Value = PAQUETE2.Item(aux - 1)
aux += 1
End While
aux = 1
While (aux <= IDCONTENEDOR.Count)
hoja1.Cells("F" & aux + 1).Value = VOLUMEN2.Item(aux - 1)
'Cambiar color de la celda ocupar este codigo'
'hoja1.Cells("A" & aux + 1).Style.Fill.PatternType = ExcelFillStyle.Solid
'hoja1.Cells("A" & aux + 1).Style.Fill.BackgroundColor.SetColor(Color.Red)
aux += 1
End While
aux = 1
excel.Save()
MsgBox("Documento Creado Correctamente", MsgBoxStyle.Information, Title:="Operacion Correcta")
Process.Start(path)
End If
End Sub
Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
LIMPIAR_VARIABLES_PLANILLA()
TextBox2.Text = ""
MsgBox("Las variables de la planilla se han limpiado correctamente", MsgBoxStyle.Information, Title:="LIMPIAR")
End Sub
Private Sub TextBox2_TextChanged(sender As Object, e As EventArgs) Handles TextBox2.TextChanged
End Sub
End Class
so as you can this does not compare the two excel and it just shows me information
Any ideas on how to do this?
Thanks in advance
you need to match the rows by combining 2 loops.
For each itemfromfile1 in file1
for each itemfromfile2 in file2
' Match 2 rows with each other
if itemfromfile1.SomeField = itemfromfile2.SomeField then
' These are the linked rows between the 2 documents
end if
next
next
Simple fill in the pseudo variables with the code that your office implementation uses.

how can i fix this error=Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index"

I have a gridview when i click the column of the dataGridview the problem show
"error=Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index""
how can i fix this? please help
this is the whole code.
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'construct dataGridview
DataGridView1.ColumnCount = 4
DataGridView1.Columns(0).Name = "name"
DataGridView1.Columns(1).Name = "position"
DataGridView1.Columns(2).Name = "team"
DataGridView1.SelectionMode = DataGridViewSelectionMode.FullColumnSelect
End Sub
Private Sub Populate(name As String, pos As String, team As String)
Dim row As String() = New String() {name, pos, team}
DataGridView1.Rows.Add(row)
End Sub
Private Sub Retrieve()
DataGridView1.Rows.Clear()
Dim sql As String = "SELECT * FROM peopleTB"
cmd = New OleDbCommand(sql, con)
Try
con.Open()
adapter = New OleDbDataAdapter(cmd)
adapter.fill(dt)
'fill dgview
For Each row In dt.Rows
Populate(row(1), row(2), row(3))
Next
con.Close()
dt.Rows.Clear()
Catch ex As Exception
MsgBox(ex.Message)
con.Close()
End Try
End Sub
Private Sub Cleartxt()
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
End Sub
'update db and dg
Private Sub UpdateDG(name As String)
Dim sql As String = "UPDATE peopleTB Set N ='" + TextBox1.Text + "',P='" + TextBox2.Text + "',T='" + TextBox3.Text + "'WHERE N= '" + name + "'"
'OPEN CON
Try
con.Open()
adapter.updateCommand = con.CreateCommand()
adapter.updateCommand.commandtext = sql
If adapter.updateCommand.executenonquery() > 0 Then
MsgBox("Success updated")
Cleartxt()
End If
con.Close()
Catch ex As Exception
MsgBox(ex.Message)
con.Close()
End Try
End Sub
Private Sub DataGridView1_MouseClick(sender As Object, e As MouseEventArgs) Handles DataGridView1.MouseClick
Dim name As String = DataGridView1.SelectedRows(0).Cells(0).Value
Dim position As String = DataGridView1.SelectedRows(0).Cells(1).Value
Dim team As String = DataGridView1.SelectedRows(0).Cells(2).Value
TextBox1.Text = name
TextBox2.Text = position
TextBox3.Text = team
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
Dim name As String = DataGridView1.SelectedRows(0).Cells(0).Value
UpdateDG(name)
End Sub
Im using ms access

multi-threaded code to check proxies

I'm suffering with this VB.Net 2017 code which is supposed to check if Proxies working or not. Sometimes it reach to an end successfully, and sometimes the program never reach and end or take lots of time to do so, although I have specified the timeout for every webrequest to be 11000... Also, the list of working proxies always has duplicates! I don't know how that happens, althoug the original (raw) list is unique!
Could you please help? This is supposed to wait till the 99 threads finished then another 99 (or the remaining threads) kick-started.
P.S. MYWEBSITE.com works for me only and it displays the IP address of the visitor, i.e. to double check if the proxy has worked fine
Imports System.Net
Imports System.IO
Imports System
Imports System.Text.RegularExpressions
Imports System.Threading
Public Class frmMain
Dim FinalWorkingProxies As New List(Of String)()
Private Sub btnBrowse_Click(sender As Object, e As EventArgs) Handles btnBrowse.Click
Control.CheckForIllegalCrossThreadCalls = False
PB.Maximum = txtRawIP.Lines.Count
PB.Value = 0
StartCheckingIP(0)
End Sub
Function StartCheckingIP(ByVal num As Integer)
For I As Integer = num To txtRawIP.Lines.Count - 1
Dim StrIPOnly As String = txtRawIP.Lines(I)
StrIPOnly = Trim(StrIPOnly.TrimStart("0"c)) 'remove any leading zeros
Try
Dim clsThreads As New System.Threading.Thread(AddressOf CheckIP)
clsThreads.Start(StrIPOnly)
Catch ex As Exception
MsgBox(I)
End Try
If (I > 0 And (I Mod 99 = 0)) Then Exit For
Next
Return True
End Function
Private Function CheckIP(ByVal Prox As String) As Boolean
'txtHTML.Text += vbCrLf & Prox
'txtHTML.Refresh()
Dim txtWebResult As String = ""
Dim OriginalFullProx As String = Trim(Prox)
Dim proxyObject As WebProxy = New WebProxy("http://" & OriginalFullProx & "/")
proxyObject.BypassProxyOnLocal = True
Prox = Prox.Substring(0, Prox.IndexOf(":"))
Dim sURL As String
sURL = "http://MYWEBSITE.com/testip.php"
Dim wrGETURL As WebRequest
wrGETURL = WebRequest.Create(sURL)
wrGETURL.Proxy = proxyObject
wrGETURL.Timeout = 6000
txtWebResult = "Dosn't work"
Try
Dim objStream As Stream
objStream = wrGETURL.GetResponse.GetResponseStream
Dim objReader As New StreamReader(objStream)
Dim sLine As String = ""
sLine = objReader.ReadLine
If Not sLine Is Nothing Then
txtWebResult = sLine
End If
txtWebResult = Regex.Replace(txtWebResult, “^\s+$[\r\n]*”, “”, RegexOptions.Multiline)
If (Trim(Prox) = Trim(txtWebResult)) Then
FinalWorkingProxies.Add(OriginalFullProx)
End If
Catch ex As Exception
txtWebResult = "Dosn't work"
End Try
If (PB.Value < PB.Maximum) Then PB.Value += 1
PB.Refresh()
If (PB.Value = PB.Maximum) Then
txtFilteredIP.Clear()
Randomize()
Dim RRR As Integer = CInt(Math.Ceiling(Rnd() * 1000)) + 1
Thread.Sleep(RRR)
If (txtFilteredIP.Text <> "") Then Return False
Dim str As String
For Each str In FinalWorkingProxies
txtFilteredIP.Text += str & vbCrLf
Next
ElseIf ((PB.Value - 1) > 0 And ((PB.Value - 1) Mod 99 = 0)) Then
StartCheckingIP(PB.Value)
End If
Return True
End Function
Private Sub txtRawIP_TextChanged(sender As Object, e As EventArgs) Handles txtRawIP.TextChanged
lblRawIPTotal.Text = "Total: " & txtRawIP.Lines.Count
End Sub
Private Sub txtFilteredIP_TextChanged(sender As Object, e As EventArgs) Handles txtFilteredIP.TextChanged
lblFilteredIPTotal.Text = "Total: " & txtFilteredIP.Lines.Count
End Sub
End Class
Here is the modified code, but it stills takes long of time to finalize long list of proxies, although I sat max concurrent connection to 2000 and timeout to 8sec. Please help. Thanks.
Public Class frmMain
Dim FinalWorkingProxies As New List(Of String)()
Private Sub btnBrowse_Click(sender As Object, e As EventArgs) Handles btnBrowse.Click
'Control.CheckForIllegalCrossThreadCalls = False
ServicePointManager.Expect100Continue = False
ServicePointManager.DefaultConnectionLimit = 2000
'ServicePointManager.Expect100Continue = True
FinalWorkingProxies.Clear()
PB.Maximum = txtRawIP.Lines.Count
PB.Value = 0
StartCheckingIP(0)
End Sub
Function StartCheckingIP(ByVal num As Integer)
For I As Integer = num To txtRawIP.Lines.Count - 1
Dim StrIPOnly As String = txtRawIP.Lines(I)
StrIPOnly = Trim(StrIPOnly.TrimStart("0"c)) 'remove any leading zeros
Try
Dim clsThreads As New System.Threading.Thread(AddressOf CheckIP)
clsThreads.Start(StrIPOnly)
Catch ex As Exception
MsgBox(I)
End Try
If (I > 0 And (I Mod 333 = 0)) Then Exit For
Next
Return True
End Function
Private Function CheckIP(ByVal Prox As String) As Boolean
'txtHTML.Text += vbCrLf & Prox
'txtHTML.Refresh()
Dim txtWebResult As String = ""
Dim OriginalFullProx As String = Trim(Prox)
Dim proxyObject As WebProxy = New WebProxy("http://" & OriginalFullProx & "/")
proxyObject.BypassProxyOnLocal = True
Prox = Prox.Substring(0, Prox.IndexOf(":"))
Dim sURL As String
sURL = "http://MYWEBSITE.com/testip.php"
Dim wrGETURL As WebRequest
wrGETURL = WebRequest.Create(sURL)
wrGETURL.Proxy = proxyObject
wrGETURL.Timeout = 8000
txtWebResult = "Dosn't work"
Try
Dim objStream As Stream
objStream = wrGETURL.GetResponse.GetResponseStream
Dim objReader As New StreamReader(objStream)
Dim sLine As String = ""
sLine = objReader.ReadLine
If Not sLine Is Nothing Then
txtWebResult = sLine
End If
txtWebResult = Regex.Replace(txtWebResult, “^\s+$[\r\n]*”, “”, RegexOptions.Multiline)
If (Trim(Prox) = Trim(txtWebResult)) Then
'Now know exact country
sURL = "http://ip-api.com/xml/" & Prox
wrGETURL = WebRequest.Create(sURL)
wrGETURL.Proxy = proxyObject
wrGETURL.Timeout = 8000
objStream = wrGETURL.GetResponse.GetResponseStream
Dim objReader2 As New StreamReader(objStream)
Dim FullCODEOFAPI As String = objReader2.ReadToEnd()
Dim XMLR As XmlReader
XMLR = XmlReader.Create(New StringReader(FullCODEOFAPI))
XMLR.ReadToFollowing("country")
XMLR.Read()
OriginalFullProx += "-" + XMLR.Value
FinalWorkingProxies.Add(OriginalFullProx)
End If
Catch ex As Exception
txtWebResult = "Dosn't work"
End Try
If (PB.Value < PB.Maximum) Then UpdatePB(1)
If (PB.Value = PB.Maximum) Then
UpdateFilteredList(1)
ElseIf ((PB.Value - 1) > 0 And ((PB.Value - 1) Mod 333 = 0)) Then
StartCheckingIP(PB.Value)
End If
Return True
End Function
Private Delegate Sub UpdatePBDelegate(ByVal PBVal As Integer)
Private Sub UpdatePB(ByVal PBVal As Integer)
If PB.InvokeRequired Then
PB.Invoke(New UpdatePBDelegate(AddressOf UpdatePB), New Object() {PBVal})
Else
PB.Value += PBVal
PB.Refresh()
End If
End Sub
Private Delegate Sub UpdateFilteredListDelegate()
Private Sub UpdateFilteredList(ByVal TMP As Integer)
If txtFilteredIP.InvokeRequired Then
txtFilteredIP.Invoke(New UpdatePBDelegate(AddressOf UpdateFilteredList), New Object() {TMP})
Else
txtFilteredIP.Clear()
Dim str As String
For Each str In FinalWorkingProxies
txtFilteredIP.Text += str & vbCrLf
Next
End If
End Sub
Private Sub txtRawIP_TextChanged(sender As Object, e As EventArgs) Handles txtRawIP.TextChanged
lblRawIPTotal.Text = "Total: " & txtRawIP.Lines.Count
End Sub
Private Sub txtFilteredIP_TextChanged(sender As Object, e As EventArgs) Handles txtFilteredIP.TextChanged
lblFilteredIPTotal.Text = "Total: " & txtFilteredIP.Lines.Count
End Sub
Private Sub btnLoadList_Click(sender As Object, e As EventArgs) Handles btnLoadList.Click
OFD.ShowDialog()
If (OFD.FileName <> "") Then
txtRawIP.Text = File.ReadAllText(OFD.FileName)
End If
End Sub
End Class

Row not found in database using vb.net

I am searching a row whose data is same as in my textbox1 but it shows the error as below.
Error snippet
Database Snippet
Code:
Imports System.Data.SqlClient
Imports WindowsApplication1.BBSRSDataSet1
Public Class CirricularDetails
Private Sub CirricularDetails_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
Public Sub CheckBox1_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox1.CheckedChanged
' Dim i As Integer
Dim a As String = "IEEE"
Dim x As Integer = 3
Try
databaseconnection()
Dim sql As String = "SELECT COUNT(*) AS rowscount FROM Curriculardb"
sqlinsertcommand = New SqlCommand(sql, connection)
Try
Dim count As Int16 = Convert.ToInt16(sqlinsertcommand.ExecuteScalar())
' BBSRSDataSet1.Tables(0).rows(count).cells(index2) = "TRUE" Then
MsgBox(count.ToString())
' For i = 0 To count - 1 Step 1 Field(Of CurriculardbDataTable)("IEEE")
Dim BBSRSDataSet1 = New BBSRSDataSet1
For i = 0 To count - 1
If BBSRSDataSet1.Tables("Curriculardb").Rows(1).ToString = TextBox1.Text Then
MsgBox("Record found")
End If
Next
Catch ex As SqlException
End Try
Catch ex As SqlException
End Try
End Sub

adding to my arraylist with out overriding it in vb

i just asked a question and i modified my my code accordingly. Something is very wrong with the way im writting my page load. my aim is to initialize the array only the first time and then to keep on incrementing it. can you help?
This is the code I used:
Imports AjaxControlToolkit
Imports System.Data.SqlClient
Imports System.Configuration
Partial Class Shtick
Inherits System.Web.UI.Page
Dim conn As SqlConnection
Dim comm As SqlCommand
Dim reader As SqlDataReader
Dim purimConnection As String = ConfigurationManager.ConnectionStrings("Purim").ConnectionString
Dim ItemSelect As New ArrayList()
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If ItemSelect.Count > 0 Then
ItemSelect = New ArrayList()
Session("itemInCart") = ItemSelect
End If
If Not IsPostBack Then
FillShtickList()
End If
End Sub
Protected Sub FillShtickList()
Dim conn As SqlConnection
Dim comm As SqlCommand
Dim reader As SqlDataReader
Dim purimConnection As String = ConfigurationManager.ConnectionStrings("Purim").ConnectionString
conn = New SqlConnection(purimConnection)
comm = New SqlCommand("SELECT RTRIM(ProductPrice) AS Price, ProductName, ProductImage, ProductID, ProductDescription FROM Products", conn)
Try
conn.Open()
reader = comm.ExecuteReader()
ShtickDataList.DataSource = reader
ShtickDataList.DataBind()
reader.Close()
Finally
conn.Close()
End Try
End Sub
'Protected Sub ShtickDataList_ItemCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.ListViewItemEventArgs) Handles ShtickDataList.ItemCreated
' 'If e.Item.ItemType = ListItemType.Item Then
' ' Dim pce As ModalPopupExtender = e.Item.FindControl("PopupControlExtender1")
' ' Dim behaviorID As String
' ' behaviorID = "pce_" & e.Item.DataItemIndex
' ' pce.BehaviorID = behaviorID
' ' Dim img As Image = e.Item.FindControl("PI")
'item select = which item was selected
Dim Quantities As New ArrayList()
Dim itemQtyOrdered As Integer
Public Sub ShtickDataList_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.ListViewCommandEventArgs) Handles ShtickDataList.ItemCommand
If e.CommandName = "ViewCart" Then
Response.Redirect("~/ShoppingCart.aspx")
End If
If e.CommandName = "addToCart" Then
Dim itemQuantity As DropDownList = e.Item.FindControl("QuantityDropDown")
itemQtyOrdered = itemQuantity.SelectedValue
ItemSelect.Add(e.CommandArgument)
Quantities.Add(itemQtyOrdered)
Session("itemInCart") = ItemSelect
Session("quantities") = Quantities
viewInvoice()
End If
End Sub
Protected Sub viewInvoice()
Dim itemSelected As ArrayList = DirectCast(Session("itemInCart"), ArrayList)
Dim QuantityofItem As ArrayList = DirectCast(Session("quantities"), ArrayList)
Dim conn As SqlConnection
Dim comm As SqlCommand
Dim reader As SqlDataReader
Dim purimConnection2 As String = ConfigurationManager.ConnectionStrings("Purim").ConnectionString
conn = New SqlConnection(purimConnection2)
comm = New SqlCommand("SELECT ProductName FROM Products WHERE ProductID = #ProductID", conn)
'Dim i As Integer
'For i = 0 To ItemSelect.Count - 1
comm.Parameters.Add("#ProductID", Data.SqlDbType.Int)
comm.Parameters("#ProductID").Value = (ItemSelected.Count - 1)
'Next
Try
conn.Open()
reader = comm.ExecuteReader()
ViewCartlink.Text = "View Cart: (" & ItemSelected.Count & ")"
Finally
conn.Close()
End Try
End Sub
End Class
End Try
End Sub
End Class
= CType(Session("itemInCart"), ArrayList)
'al.Add(SS)
'Session.Add("itemInCart", al)
viewInvoice()
End If
End Sub
Protected Sub viewInvoice()
'Dim itemSelected As ArrayList = DirectCast(Session("itemInCart"), ArrayList)
'Dim QuantityofItem As ArrayList = DirectCast(Session("quantities"), ArrayList)
Dim conn As SqlConnection
Dim comm As SqlCommand
Dim reader As SqlDataReader
Dim purimConnection2 As String = ConfigurationManager.ConnectionStrings("Purim").ConnectionString
conn = New SqlConnection(purimConnection2)
comm = New SqlCommand("SELECT ProductName FROM Products WHERE ProductID = #ProductID", conn)
Dim i As Integer
For i = 0 To ItemSelect.Count - 1
comm.Parameters.Add("#ProductID", Data.SqlDbType.Int)
comm.Parameters("#ProductID").Value = ItemSelect(i)
Next
Try
conn.Open()
reader = comm.ExecuteReader()
ViewCartlink.Text = "View Cart: (" & ItemSelect.Count & ")"
Finally
conn.Close()
End Try
End Sub
End Class
M(ProductPrice) AS Price, ProductID, ProductName FROM Products WHERE ProductID = #ProductID", conn)
comm = New SqlCommand("Insert into orders (UserID, ProductID, quantity) values (1, #ProductID, #Quantity)", conn)
comm.Parameters.Add("#ProductID", Data.SqlDbType.Int)
comm.Parameters("#ProductID").Value = item
comm.Parameters.Add("#Quantity", Data.SqlDbType.Int)
comm.Parameters("#Quantity").Value = qty
'Dim i As Integer
'For i = 0 To ItemSelect.Length - 1
' comm.Parameters.Add("#ProductID", Data.SqlDbType.Int)
' comm.Parameters("#ProductID").Value = ItemSelect(i)
'Next
Try
conn.Open()
comm.ExecuteNonQuery()
'reader = comm.ExecuteReader()
'ShoppingList.DataSource = reader
'ShoppingList.DataBind()
'reader.Close()
Finally
conn.Close()
End Try
End Sub
In the code:
If ItemSelect.Count > 0 Then
ItemSelect = New ArrayList()
Session("itemInCart") = ItemSelect
End If
You have a more than where you should have a less than. The arraylist only initialises when there is an item in the array. So you only initialise the array after it is initialised. WHat you need is:
If ItemSelect.Count > 0 Then
ItemSelect = New ArrayList()
Session("itemInCart") = ItemSelect
End If