Accessviolationexception was unhandled vb.net in Savefile Dialog - vb.net

Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
I got this error when I filter my datagridview by date and save it as .dat file.
Dim sv As New SaveFileDialog()
sv.FilterIndex = 2
sv.RestoreDirectory = True
sv.FileName = ""
sv.Filter = "Text Document |*.dat"
sv.Title = "Save as"
Dim mm As String = DateTimePicker1.Value.Month
Dim yy As String = DateTimePicker1.Value.Year
Dim dd As String = mm & yy
sv.FileName = "123456789" & "P" & dd
If sv.ShowDialog = DialogResult.OK Then
Dim writer As TextWriter = New System.IO.StreamWriter(sv.FileName)
writer.Write("H,P," & "123456789" & "," & "ABC CORP" & "," & "DELA CRUZ" & "," & "JUAN POGI" & "," & "MADLANGTUTA" & "," & "ABC CORP TRADENAME" & "," & "BATANGAS CITY" & "," & "BATANGAS PROVINCE" & " " & "4200" & "," & totalExempt & "," & totalZeroRated & "," & totalServices & "," & totalCapitalGoods & "," & totalGoodsOther & "," & totalInputTax & "," & Creditable & "," & totalNonCreditable & "," & "058" & "," & DateTimePicker1.Text & "," & "12")
writer.WriteLine("")
For i As Integer = 0 To DataGridView1.Rows.Count - 1 Step +1
writer.Write("D,P" & ",")
For j As Integer = 0 To 12
writer.Write(DataGridView1.Rows(i).Cells(j).Value.ToString() & ",")
Next
writer.Write("123456789" & "," & DateTimePicker1.Text)
writer.WriteLine("")
Next
writer.Close()
MsgBox("Generated Successfully", MsgBoxStyle.Information, "Transaction Complete")
End If
https://drive.google.com/file/d/18lODhowILSuyl7zKZyJ55cH9U9DvL393/view
here is the screen recording of my project
enter code here
'' this is my code for filter
Call connectDB()
Try
con.Open()
cmd = New OleDbCommand("select colDate, colSupplierTin, ColSupplierName, colLastName, colFirstName, colMiddleName, colAddress1, colAddress2, colExempt, colZeroRated,colDomesticServices,colCapitalGood, colDomesticGoods, colInputTax,colNetofvat from tblPurchases where colDate like '%" + DateTimePicker1.Text + "%'", con)
adp = New OleDbDataAdapter(cmd)
Dim table As New DataTable()
adp.Fill(table)
DataGridView1.DataSource = table
Dim src As New BindingSource
src.DataSource = DataGridView1.DataSource
DataGridView1.Columns(0).HeaderText = "DATE"
DataGridView1.Columns(0).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
DataGridView1.Columns(0).SortMode = DataGridViewColumnSortMode.Programmatic
DataGridView1.Columns(1).HeaderText = "SUPPLIER TIN"
DataGridView1.Columns(1).AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells
DataGridView1.Columns(1).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
DataGridView1.Columns(1).SortMode = DataGridViewColumnSortMode.Programmatic
DataGridView1.Columns(2).HeaderText = "SUPPLIER NAME"
DataGridView1.Columns(2).AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells
DataGridView1.Columns(2).SortMode = DataGridViewColumnSortMode.Programmatic
DataGridView1.Columns(3).HeaderCell.Value = "LAST NAME"
DataGridView1.Columns(3).AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells
DataGridView1.Columns(3).SortMode = DataGridViewColumnSortMode.Programmatic
DataGridView1.Columns(3).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
DataGridView1.Columns(4).HeaderCell.Value = "FIRST NAME"
DataGridView1.Columns(4).AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells
DataGridView1.Columns(4).SortMode = DataGridViewColumnSortMode.Programmatic
DataGridView1.Columns(4).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft
DataGridView1.Columns(5).HeaderCell.Value = "MIDDLE NAME"
DataGridView1.Columns(5).AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells
DataGridView1.Columns(5).SortMode = DataGridViewColumnSortMode.Programmatic
DataGridView1.Columns(5).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft
DataGridView1.Columns(6).HeaderCell.Value = "BARANGAY / SUBSTREET"
DataGridView1.Columns(6).AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells
DataGridView1.Columns(6).SortMode = DataGridViewColumnSortMode.Programmatic
DataGridView1.Columns(6).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft
DataGridView1.Columns(7).HeaderCell.Value = "CITY / PROVINCE"
DataGridView1.Columns(7).AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells
DataGridView1.Columns(7).SortMode = DataGridViewColumnSortMode.Programmatic
DataGridView1.Columns(8).HeaderCell.Value = "EXEMPT PURCHASES"
DataGridView1.Columns(8).AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells
DataGridView1.Columns(8).SortMode = DataGridViewColumnSortMode.Programmatic
DataGridView1.Columns(9).HeaderCell.Value = "ZERO-RATED PURCHASES"
DataGridView1.Columns(9).AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells
DataGridView1.Columns(9).DefaultCellStyle.Alignment = DataGridViewContentAlignment.BottomCenter
DataGridView1.Columns(9).SortMode = DataGridViewColumnSortMode.Programmatic
DataGridView1.Columns(10).HeaderCell.Value = "DOMESTIC SERVICES"
DataGridView1.Columns(10).AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells
DataGridView1.Columns(10).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
DataGridView1.Columns(10).SortMode = DataGridViewColumnSortMode.Programmatic
DataGridView1.Columns(11).HeaderCell.Value = "CAPITAL GOODS"
DataGridView1.Columns(11).AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells
DataGridView1.Columns(11).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
DataGridView1.Columns(11).SortMode = DataGridViewColumnSortMode.Programmatic
DataGridView1.Columns(12).HeaderCell.Value = "GOODS OTHER THAN CAPITAL GOODS"
DataGridView1.Columns(12).AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells
DataGridView1.Columns(12).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
DataGridView1.Columns(12).SortMode = DataGridViewColumnSortMode.Programmatic
DataGridView1.Columns(13).HeaderCell.Value = "TOTAL INPUT TAX"
DataGridView1.Columns(13).AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells
DataGridView1.Columns(13).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
DataGridView1.Columns(13).SortMode = DataGridViewColumnSortMode.Programmatic
DataGridView1.Columns(14).HeaderCell.Value = "TAXABLE NET OF VAT"
DataGridView1.Columns(14).AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells
DataGridView1.Columns(14).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
DataGridView1.Columns(14).SortMode = DataGridViewColumnSortMode.Programmatic
DataGridView1.Columns(14).DefaultCellStyle.Format = "c"
Catch ex As Exception
MsgBox(ex.Message)
End Try
Call Computation()
con.Close()

Related

VBA/Access: How to stop "You... FORM to be active window"

I want to be able to tell IF a form is the active window.
It seems simply invoking that method produces an error. I guess I could catch that error and run with it, but it's a backwards way of doing it.
Screen.ActiveForm.Name
This needs a form to be active. If I am breaking any rules of stackOverflow please be kind and remind me as I am new to forum.
Screen.parent, screen.activeControl, etc. What if VBA editor is open, as often it is?
Function CStatus(strStatus, ByRef intType As Integer, Optional ByRef erNo, Optional erMsg, Optional strDatum)
'pXname = "CStatus"
'pXStack = Left(pXStack, 500) & ">" & pXname
'Updates and manages the status bar
Dim strPreamble As String, strOut As String, strForm As String, strComment As String, strSQL As String, strPxStack As String, strCErrStack As String
Dim intColor As Double
Dim intPreLen As Integer
'On Error GoTo err_hand
'Color Codes
'12632256 = Lt Grey
'33023 = Orange
'65280 = Green
'16744576 = Steel Grey
'Define "Constants"
intPreLen = 350 'Length of previous message cache
'** Fix missings
If (IsMissing(strDatum) = True) Then strDatum = "[N/A]"
'** Other inits
strWindow = Screen.Parent.Name
strForm = Screen.ActiveForm.Name
'** intDebug ' Minimum Level of to report to status
'bEcho = True 'Whether to echo to status
intColor = errNoColor(intType)
'Error-level idiot explanations
strComment = "0"
If IsMissing(erNo) Then erNo = 0
If (IsNull(erMsg) = False) Then
If IsMissing(erMsg) = False Then strComment = erMsg
End If
strComment = errorTree(erNo)
strPreamble = Left(strPreamble, intPreLen) & "..."
strErrStack = Left(strErrStack, intPreLen) & " > " & pXname & ":" & intType
strCErrStack = strErrStack
reS:
If ((strForm = "finvmain") Or (strForm = "fclips")) Then Screen.ActiveForm.timeStatusUpdated = Now() 'Small field keeps time
If bEcho = True Then
strPxStack = ""
strCErrStack = "" 'Internal error stack
End If
strOut = Now() & " " & intType & " (" & strType & "): " & erNo & " " & strCErrStack & " >> " & strComment & " / " & strStatus & " [" & strDatum & "] .. " & strPreamble
If bEcho = True Then
If (strForm = "fInvMain") Then Screen.ActiveForm.txtStatus2 = Screen.ActiveForm.txtStatus 'Added second window to show previous message
Screen.ActiveForm.txtStatus = strOut
End If
Screen.ActiveForm.txtStatus.ForeColor = intColor
If strForm = "fInvMain" Then strTag = Screen.ActiveForm.Controls("txttag").value
'***Event Log
If erNo = "" Then erNo = 0
If IsMissing(erMsg) = True Then erMsg = ""
If IsMissing(strDatum) = True Then strDatum = ""
If Len(strPreamble) < 2 Then strPreamble = "[None]"
'Fixxed - Syntax Error for Some Odd Reason! Apr 27th
If ((strTag = Empty) And (strForm = "fInvMain")) Then strTag = Screen.ActiveForm.txtTag 'Attempt to add tag# to entry
strStatus = cleanString(strStatus)
strDatum = cleanString(strDatum)
strComment = cleanString(strComment)
strSQL = "INSERT INTO tEvents(txtdate, myerrno, interrno, myerrmsg, interrmsg, txtform, stack, process, Datum, idLink) VALUES ('" & Now() & "','" & intType & "','" & erNo & "','" & strStatus & "','" & strComment & "','" & strForm & "','" & strErrStack & "','" & pXname & "','" & strDatum & "','" & strTag & "');"
CurrentDb.Execute strSQL, dbFailOnError
Exit Function
err_hand:
If Err.Number = 2475 Then
bEcho = False
Resume reS
Else: MsgBox "555: CStatus Internal Error, Turn off error handling to view"
End If
End Function
I need a boolean true or false IF form is active. If it isn't, I can't put stuff into a textbox in that.
To determine if a particular form is open then set focus to form:
If CurrentProject.AllForms("finvmain").IsLoaded
strForm = "finvmain"
Elseif CurrentProject.AllForms("fclips").IsLoaded Then
strForm = "fclips"
End If
If strForm <> "" Then DoCmd.SelectObject acForm, strForm

Crystal report export cause not responding

I built a desktop application using VB.NET on Visual Studio 2012. I use Crystal Report to show the report. But when user generated the report and try to export into another file (excel,etc), it always cause my application "Not responding" and closing the application.
Is this memory problem or I have to install something else?
my code to load report in reportviewer controller
Thread.CurrentThread.CurrentCulture = New CultureInfo("id-ID")
Thread.CurrentThread.CurrentCulture.NumberFormat.CurrencySymbol = "Rp "
Thread.CurrentThread.CurrentCulture.DateTimeFormat.DateSeparator = "-"
Thread.CurrentThread.CurrentCulture.DateTimeFormat.FullDateTimePattern = "dd/MM/yyyy hh:mm:ss"
Dim PeriodeAwal As DateTime
Dim PeriodeAkhir As DateTime
If lblTodayOrMonth.Text.ToLower = "custom" Then
PeriodeAwal = New DateTime(frmJenisLaporan.dtpAwal.Value.Year, frmJenisLaporan.dtpAwal.Value.Month, frmJenisLaporan.dtpAwal.Value.Day)
PeriodeAkhir = New DateTime(frmJenisLaporan.dtpAkhir.Value.Year, frmJenisLaporan.dtpAkhir.Value.Month, frmJenisLaporan.dtpAkhir.Value.Day)
End If
If conn.State = ConnectionState.Closed Then
conn.Open()
End If
Dim ds As DataSet = New DataSet
Dim t As DataTable = ds.Tables.Add("Transaksi")
Dim r As DataRow
t.Columns.Add("IDHORDER", Type.GetType("System.Int32"))
t.Columns.Add("TANGGAL", Type.GetType("System.DateTime"))
t.Columns.Add("NOINVOICE", Type.GetType("System.String"))
t.Columns.Add("MEJA", Type.GetType("System.String"))
t.Columns.Add("Total", Type.GetType("System.Decimal"))
t.Columns.Add("Diskon", Type.GetType("System.Decimal"))
t.Columns.Add("TotalBersih", Type.GetType("System.Decimal"))
t.Columns.Add("PEMBAYARAN", Type.GetType("System.Decimal"))
t.Columns.Add("KEMBALIAN", Type.GetType("System.Decimal"))
t.Columns.Add("JENISORDER", Type.GetType("System.String"))
t.Columns.Add("CREATEDBY", Type.GetType("System.String"))
t.Columns.Add("PAX", Type.GetType("System.String"))
t.Columns.Add("NAMA", Type.GetType("System.String"))
t.Columns.Add("IDDORDER", Type.GetType("System.Int32"))
t.Columns.Add("IDMENU", Type.GetType("System.Int32"))
t.Columns.Add("QTY", Type.GetType("System.Int32"))
t.Columns.Add("HARGASAATORDER", Type.GetType("System.Decimal"))
t.Columns.Add("SUBTOTAL", Type.GetType("System.Decimal"))
t.Columns.Add("NAMAMENU", Type.GetType("System.String"))
t.Columns.Add("NAMARESTORAN", Type.GetType("System.String"))
t.Columns.Add("REVISIORNOT", Type.GetType("System.String"))
t.Columns.Add("SERVICECHARGE", Type.GetType("System.Decimal"))
t.Columns.Add("LOGOLOCATION", Type.GetType("System.String"))
t.Columns.Add("PAJAK", Type.GetType("System.Decimal"))
t.Columns.Add("ALASANDISKON", Type.GetType("System.String"))
t.Columns.Add("DISKONBY", Type.GetType("System.String"))
t.Columns.Add("CUSTOMERNAME", Type.GetType("System.String"))
t.Columns.Add("GETPOIN", Type.GetType("System.Int32"))
t.Columns.Add("CUSTOMERTOTALPOIN", Type.GetType("System.Int32"))
t.Columns.Add("DISKONEXTRA", Type.GetType("System.Decimal"))
Dim counterJumlahPorsi As Integer = 0
Dim TotalNominal As Decimal = 0
'ambil data transaksi
'cmdtxt = "SELECT H.IDHORDER, H.TANGGAL, H.NOINVOICE, H.MEJA, H.TOTAL, H.DISKON, H.TOTALBERSIH, H.PEMBAYARAN, H.KEMBALIAN, H.JENISORDER, H.CREATEDBY, H.PAX, H.NAMA, D.IDDORDER, D.IDMENU, D.QTY, D.HARGASAATORDER, D.SUBTOTAL, M.NAMAMENU, H.SERVICECHARGE,H.PAJAK,H.ALASANDISKON,H.DISKONBY FROM HORDER AS H, DORDER AS D, MENU AS M WHERE (((M.IDMENU)=[D].[IDMENU]) AND ((D.IDHORDER)=[H].[IDHORDER])) AND COMPLETED=True AND KEEPRECORD=True"
cmdtxt = "SELECT H.IDHORDER, H.TANGGAL, H.NOINVOICE, H.MEJA, H.TOTAL, H.DISKON, H.TOTALBERSIH, H.PEMBAYARAN, H.KEMBALIAN, H.JENISORDER, H.CREATEDBY, H.PAX, H.NAMA, D.IDDORDER, D.IDMENU, D.QTY, D.HARGASAATORDER, D.SUBTOTAL, M.NAMAMENU, H.SERVICECHARGE,H.PAJAK,H.ALASANDISKON,H.DISKONBY, H.GETPOIN, IIF(H.IDCUSTOMER=0,'Non Member',C.NAMACUSTOMER) AS NAMACUSTOMER,H.DISKONEXTRA FROM ((HORDER AS H INNER JOIN DORDER AS D ON D.IDHORDER=H.IDHORDER) INNER JOIN MENU AS M ON M.IDMENU=D.IDMENU) LEFT JOIN CUSTOMER AS C ON C.IDCUSTOMER=H.IDCUSTOMER WHERE H.COMPLETED=TRUE AND H.KEEPRECORD=TRUE"
If lblTodayOrMonth.Text.ToLower = "today" Then
cmdtxt &= " AND DAY(H.TANGGAL)=" & Date.Now.Day & " AND MONTH(H.TANGGAL)=" & Date.Now.Month & " AND YEAR(H.TANGGAL)=" & Date.Now.Year
ElseIf lblTodayOrMonth.Text.ToLower = "month" Then
cmdtxt &= " AND MONTH(H.TANGGAL)=" & Date.Now.Month & " AND YEAR(H.TANGGAL)=" & Date.Now.Year
ElseIf lblTodayOrMonth.Text.ToLower = "custom" Then
'cmdtxt &= " AND DATEVALUE('" & PeriodeAwal & "')<=H.TANGGAL AND H.TANGGAL<=DATEVALUE('" & PeriodeAkhir.AddDays(1) & "')"
cmdtxt &= " AND DATEVALUE('" & PeriodeAwal.Month & "-" & PeriodeAwal.Day & "-" & PeriodeAwal.Year & "')<=H.TANGGAL AND H.TANGGAL<=DATEVALUE('" & PeriodeAkhir.AddDays(1).Month & "-" & PeriodeAkhir.AddDays(1).Day & "-" & PeriodeAkhir.AddDays(1).Year & "')"
End If
cmd = New OleDbCommand(cmdtxt, conn)
reader = cmd.ExecuteReader
If reader.HasRows Then
While reader.Read
r = t.NewRow()
r("IDHORDER") = reader.GetValue(0)
r("TANGGAL") = reader.GetValue(1)
r("NOINVOICE") = reader.GetValue(2)
Dim totalMeja() As String = reader.GetValue(3).ToString.Split(",")
r("MEJA") = totalMeja(0)
r("Total") = reader.GetValue(4)
r("Diskon") = reader.GetValue(5)
r("TotalBersih") = reader.GetValue(6)
r("PEMBAYARAN") = reader.GetValue(7)
r("KEMBALIAN") = reader.GetValue(8)
r("JENISORDER") = reader.GetValue(9)
r("CREATEDBY") = reader.GetValue(10)
r("PAX") = reader.GetValue(11)
r("NAMA") = reader.GetValue(12)
r("IDDORDER") = reader.GetValue(13)
r("IDMENU") = reader.GetValue(14)
r("QTY") = reader.GetValue(15)
r("HARGASAATORDER") = reader.GetValue(16)
r("SUBTOTAL") = reader.GetValue(17)
r("NAMAMENU") = reader.GetValue(18)
r("NAMARESTORAN") = NamaRestoran
r("SERVICECHARGE") = reader.GetValue(19)
r("LOGOLOCATION") = LogoRestoran
r("PAJAK") = reader.GetValue(20)
r("ALASANDISKON") = reader.GetValue(21)
r("DISKONBY") = reader.GetValue(22)
r("GETPOIN") = reader.GetValue(23)
r("CUSTOMERNAME") = reader.GetValue(24)
r("CUSTOMERTOTALPOIN") = 0
r("DISKONEXTRA") = reader.GetValue(25)
t.Rows.Add(r)
counterJumlahPorsi += reader.GetValue(15)
End While
End If
reader.Close()
'hitung total Nominal Penjualan
cmdtxt = "SELECT H.TOTALBERSIH FROM HORDER AS H WHERE COMPLETED=True AND KEEPRECORD=True"
If lblTodayOrMonth.Text.ToLower = "today" Then
cmdtxt &= " AND DAY(H.TANGGAL)=" & Date.Now.Day & " AND MONTH(H.TANGGAL)=" & Date.Now.Month & " AND YEAR(H.TANGGAL)=" & Date.Now.Year
ElseIf lblTodayOrMonth.Text.ToLower = "month" Then
cmdtxt &= " AND MONTH(H.TANGGAL)=" & Date.Now.Month & " AND YEAR(H.TANGGAL)=" & Date.Now.Year
ElseIf lblTodayOrMonth.Text.ToLower = "custom" Then
cmdtxt &= " AND DATEVALUE('" & PeriodeAwal.Month & "-" & PeriodeAwal.Day & "-" & PeriodeAwal.Year & "')<=H.TANGGAL AND H.TANGGAL<=DATEVALUE('" & PeriodeAkhir.AddDays(1).Month & "-" & PeriodeAkhir.AddDays(1).Day & "-" & PeriodeAkhir.AddDays(1).Year & "')"
End If
cmd = New OleDbCommand(cmdtxt, conn)
reader = cmd.ExecuteReader
While reader.Read
TotalNominal += reader.GetValue(0)
End While
reader.Close()
Dim trptTotal As DataTable = ds.Tables.Add("TotalMenuSold")
Dim rrptTotal As DataRow
trptTotal.Columns.Add("IDHORDER", Type.GetType("System.Int32"))
trptTotal.Columns.Add("IDMENU", Type.GetType("System.Int32"))
trptTotal.Columns.Add("NAMAMENU", Type.GetType("System.String"))
trptTotal.Columns.Add("HARGAJUAL", Type.GetType("System.Decimal"))
trptTotal.Columns.Add("TANGGAL", Type.GetType("System.String"))
trptTotal.Columns.Add("QTY", Type.GetType("System.Int32"))
trptTotal.Columns.Add("SUBTOTAL", Type.GetType("System.Decimal"))
trptTotal.Columns.Add("TOTALDISKONMEMBER", Type.GetType("System.Decimal"))
trptTotal.Columns.Add("TOTALDISKONEXTRA", Type.GetType("System.Decimal"))
trptTotal.Columns.Add("TOTALPAJAK", Type.GetType("System.Decimal"))
'ambil total diskon
Dim varTotalDiskonMember As Decimal = 0
Dim vartotalDiskonExtra As Decimal = 0
Dim vartotalPajak As Decimal = 0
cmdtxt = "SELECT SUM(DISKON) AS 'TOTALDISKONMEMBER',SUM(DISKONEXTRA) AS 'TOTALDISKONEXTRA',SUM(PAJAK) AS 'TOTALPAJAK' FROM HORDER H WHERE h.COMPLETED=True AND h.KEEPRECORD=True "
If lblTodayOrMonth.Text.ToLower = "today" Then
cmdtxt &= " AND DAY(H.TANGGAL)=" & Date.Now.Day & " AND MONTH(H.TANGGAL)=" & Date.Now.Month & " AND YEAR(H.TANGGAL)=" & Date.Now.Year
ElseIf lblTodayOrMonth.Text.ToLower = "month" Then
cmdtxt &= " AND MONTH(H.TANGGAL)=" & Date.Now.Month & " AND YEAR(H.TANGGAL)=" & Date.Now.Year
ElseIf lblTodayOrMonth.Text.ToLower = "custom" Then
cmdtxt &= " AND DATEVALUE('" & PeriodeAwal.Month & "-" & PeriodeAwal.Day & "-" & PeriodeAwal.Year & "')<=H.TANGGAL AND H.TANGGAL<=DATEVALUE('" & PeriodeAkhir.AddDays(1).Month & "-" & PeriodeAkhir.AddDays(1).Day & "-" & PeriodeAkhir.AddDays(1).Year & "')"
End If
cmd = New OleDbCommand(cmdtxt, conn)
reader = cmd.ExecuteReader
If reader.HasRows Then
reader.Read()
varTotalDiskonMember = reader.GetValue(0)
vartotalDiskonExtra = reader.GetValue(1)
vartotalPajak = reader.GetValue(2)
End If
reader.Close()
'ambil total menu terjual
cmdtxt = "SELECT m.IDMENU, m.NAMAMENU, m.HARGAJUAL, SUM(d.QTY) as 'SOLD' FROM MENU M, HORDER H, DORDER D WHERE h.COMPLETED=True AND h.KEEPRECORD=True AND M.IDMENU=D.IDMENU AND H.IDHORDER=D.IDHORDER "
If lblTodayOrMonth.Text.ToLower = "today" Then
cmdtxt &= " AND DAY(H.TANGGAL)=" & Date.Now.Day & " AND MONTH(H.TANGGAL)=" & Date.Now.Month & " AND YEAR(H.TANGGAL)=" & Date.Now.Year
ElseIf lblTodayOrMonth.Text.ToLower = "month" Then
cmdtxt &= " AND MONTH(H.TANGGAL)=" & Date.Now.Month & " AND YEAR(H.TANGGAL)=" & Date.Now.Year
ElseIf lblTodayOrMonth.Text.ToLower = "custom" Then
cmdtxt &= " AND DATEVALUE('" & PeriodeAwal.Month & "-" & PeriodeAwal.Day & "-" & PeriodeAwal.Year & "')<=H.TANGGAL AND H.TANGGAL<=DATEVALUE('" & PeriodeAkhir.AddDays(1).Month & "-" & PeriodeAkhir.AddDays(1).Day & "-" & PeriodeAkhir.AddDays(1).Year & "')"
End If
cmdtxt &= " GROUP BY M.IDMENU,M.NAMAMENU, M.HARGAJUAL"
cmd = New OleDbCommand(cmdtxt, conn)
reader = cmd.ExecuteReader
If reader.HasRows Then
While reader.Read
rrptTotal = trptTotal.NewRow()
rrptTotal("IDHORDER") = -1
rrptTotal("IDMENU") = reader.GetValue(0)
rrptTotal("NAMAMENU") = reader.GetValue(1)
rrptTotal("HARGAJUAL") = reader.GetValue(2)
rrptTotal("QTY") = reader.GetValue(3)
rrptTotal("SUBTOTAL") = reader.GetValue(2) * reader.GetValue(3)
rrptTotal("TOTALDISKONMEMBER") = varTotalDiskonMember
rrptTotal("TOTALDISKONEXTRA") = vartotalDiskonExtra
rrptTotal("TOTALPAJAK") = vartotalPajak
trptTotal.Rows.Add(rrptTotal)
End While
End If
reader.Close()
Dim rptTotal As New crTotalMenuSold
rptTotal.Subreports(0).SetDataSource(ds.Tables(0)) ' define table data for sub report
rptTotal.SetDataSource(ds.Tables(1))
'Isi total porsi terjual per periode laporan
Dim crParamDefinitions As ParameterFieldDefinitions
Dim paramDefinition As ParameterFieldDefinition
Dim crParamValues As New ParameterValues
Dim paramFieldValue As New ParameterDiscreteValue
paramFieldValue.Value = counterJumlahPorsi
crParamDefinitions = rptTotal.Subreports(0).DataDefinition.ParameterFields
paramDefinition = crParamDefinitions.Item("TotalPorsi")
crParamValues = paramDefinition.CurrentValues
crParamValues.Clear()
crParamValues.Add(paramFieldValue)
paramDefinition.ApplyCurrentValues(crParamValues)
paramDefinition = crParamDefinitions.Item("PeriodeLaporan")
crParamValues = New ParameterValues
crParamValues = paramDefinition.CurrentValues
crParamValues.Clear()
paramFieldValue = New ParameterDiscreteValue
If lblTodayOrMonth.Text.ToLower = "today" Then
paramFieldValue.Value = "HARI INI"
ElseIf lblTodayOrMonth.Text.ToLower = "month" Then
paramFieldValue.Value = "BULAN INI"
ElseIf lblTodayOrMonth.Text.ToLower = "custom" Then
paramFieldValue.Value = PeriodeAwal.ToString("dd MMM yyyy") & " - " & PeriodeAkhir.ToString("dd MMM yyyy")
End If
crParamValues.Add(paramFieldValue)
paramDefinition.ApplyCurrentValues(crParamValues)
paramDefinition = crParamDefinitions.Item("TotalDalamRupiah")
crParamValues = New ParameterValues
crParamValues = paramDefinition.CurrentValues
crParamValues.Clear()
paramFieldValue = New ParameterDiscreteValue
paramFieldValue.Value = TotalNominal
crParamValues.Add(paramFieldValue)
paramDefinition.ApplyCurrentValues(crParamValues)
'===========================================================
'Isi total porsi terjual per periode laporan
Dim crParamDefinitionsrptTotal As ParameterFieldDefinitions
Dim paramDefinitionrptTotal As ParameterFieldDefinition
Dim crParamValuesrptTotal As ParameterValues
Dim paramFieldValuerptTotal As ParameterDiscreteValue
crParamDefinitionsrptTotal = rptTotal.DataDefinition.ParameterFields
paramDefinitionrptTotal = crParamDefinitionsrptTotal.Item("PeriodeLaporan")
crParamValuesrptTotal = New ParameterValues
crParamValuesrptTotal = paramDefinitionrptTotal.CurrentValues
crParamValuesrptTotal.Clear()
paramFieldValuerptTotal = New ParameterDiscreteValue
If lblTodayOrMonth.Text.ToLower = "today" Then
paramFieldValuerptTotal.Value = "HARI INI"
ElseIf lblTodayOrMonth.Text.ToLower = "month" Then
paramFieldValuerptTotal.Value = "BULAN INI"
ElseIf lblTodayOrMonth.Text.ToLower = "custom" Then
paramFieldValuerptTotal.Value = PeriodeAwal.ToString("dd MMM yyyy") & " - " & PeriodeAkhir.ToString("dd MMM yyyy")
End If
crParamValuesrptTotal.Add(paramFieldValuerptTotal)
paramDefinitionrptTotal.ApplyCurrentValues(crParamValuesrptTotal)
'===========================================================
rptViewer.ReportSource = rptTotal
rptViewer.Refresh()
If conn.State = ConnectionState.Open Then
conn.Close()
End If

Join Three Table in QODBC

I didn't get any error but there is no data that is displaying in the datagridview . Is there anything that i should add in my codes ? so it will display the data that i need ?
If MSG = vbYes Then
Timer1.Enabled = True
Me.stpLoadBar.Value = 0
Me.stpLoadBar.Value = increment
'Me.lstSearch.Items.Clear()
If Me.txtRefFR.Text = "" Or Me.txtRefTO.Text = "" Then
MessageBox.Show("Check Number is required and must not be blank.")
'Me.cmdPrint.Enabled = False
ElseIf CInt(Me.txtRefFR.Text) > CInt(Me.txtRefTO.Text) Then
MessageBox.Show("Check Number From must not be greater than Check Number To.")
Me.txtRefFR.Text = ""
Me.txtRefTO.Text = ""
Else
If Me.chkEnterBill.Checked = True Then
strSelect = "SELECT billpaymentcheckline.Txnnumber, billpaymentcheckline.payeeentityreffullname, billpaymentcheckline.txndate, billpaymentcheckline.bankaccountreffullname , billexpenseline.memo " _
& ", billpaymentcheckline.amount, billpaymentcheckline.refnumber, billpaymentcheckline.appliedtotxnrefnumber, billpaymentcheckline.appliedtotxntxndate, billpaymentcheckline.appliedtotxnamount from billpaymentcheckline INNER JOIN BillExpenseLine ON (billpaymentcheckline.appliedtotxnrefnumber = billexpenseline.refnumber) WHERE" _
& " billpaymentcheckline.refnumber BETWEEN '" & CInt(Me.txtRefFR.Text) & "' AND '" & CInt(Me.txtRefTO.Text) & "' AND" _
& " billpaymentcheckline.bankaccountreffullname='" & Me.lblBankName.Text & "'ORDER BY billpaymentcheckline.refnumber"
Try
Dim conChk As New Odbc.OdbcConnection(My.Settings.strConn)
conChk.Open()
Dim cmdChk As New Odbc.OdbcCommand(strSelect, conChk)
cmdChk.CommandType = CommandType.Text
Dim daChk As New Odbc.OdbcDataAdapter(cmdChk)
daChk.Fill(dsCVI, "tblvoucheritem")
With dgvCV
.RowsDefaultCellStyle.BackColor = Color.White
.AlternatingRowsDefaultCellStyle.BackColor = Color.DeepSkyBlue
.DataSource = dsCVI.Tables("tblvoucheritem")
.ReadOnly = True
End With
daChk.Dispose()
cmdChk.Dispose()
conChk.Close()
Me.rbCheck.Enabled = True
Me.rbCV.Enabled = True
Catch ex As Exception
MessageBox.Show(ex.Message)
Me.rbCheck.Enabled = False
Me.rbCV.Enabled = False
Finally
End Try
Me.stpLoadBar.Value = 100

vb.net Read and write data to ms database using Odbc(ERROR)

When I try to run the program, an error shows " ERROR[07002][Microsoft][ODBC MICROSOFT ACCESS DRIVER] TOO FEW PARAMETERS.EXPECTED 1" USING THIS CONNECTION.
Public Sub open_connection ()
Try
con = New OdbcConnection("dsn = LocalDB")
con.Open()
End try
Catch ex As Exception
MsgBox(ex.message)
End sub
Problems occurs when inserting and reading..
sSql = "select * from Faculty where RFID='" & txtrfid.Text & "'"
Dim cmd As New OdbcCommand(sSql, con)
Dim dr As OdbcDataReader = cmd.ExecuteReader()
If dr.HasRows Then
dr.Read()
txtfname.Text = dr("fname").ToString()
txtlname.Text = dr("lname").ToString()
txtid.Text = dr("STID").ToString()
txtposition.Text = dr("Pstion").ToString()
txtsubject.Text = dr("Subject").ToString()
Dim bits As Byte() = CType(dr("Pfile"), Byte())
Dim memo As New MemoryStream(bits)
Dim myimg As New Bitmap(memo)
imgRetrieve.Image = myimg
dr.Close()
sSql = " SELECT TOP 1 flag_inout FROM Attendance where faculty_id = #StId ORDER BY Attendance_id DESC"
Dim pcmd As New OdbcCommand(sSql, con)
pcmd.Parameters.AddWithValue("#StId", txtid.Text)
Dim pdr As OdbcDataReader = pcmd.ExecuteReader()
While pdr.Read()
TextBox1.Text = pdr("flag_inout").ToString()
End While
If TextBox1.Text = "IN" Then
TextBox1.Text = "OUT"
ElseIf TextBox1.Text = "OUT" Then
TextBox1.Text = "IN"
ElseIf TextBox1.Text = Nothing Then
TextBox1.Text = "IN"
End If
pdr.Close()
'Check Duplicate
'If txtfname.Text.Length = 0 Then
' Return
'End If
'If Not CheckDateDuplicate() Then
' MessageBox.Show("Already Saved on this Date")
' Return
'End If
sSql = "insert into Attendance (faculty_id, faculty_Fname,faculty_Lname,[Position],Subject, attendance_date, attendance_time, flag_inout) values('" & txtid.Text & "','" & txtfname.Text & "','" & txtlname.Text & "','" & txtposition.Text & "','" & txtsubject.Text & "','" & DateTimePicker1.Value.Date & "','" & TimeOfDay.ToShortTimeString & "','" & TextBox1.Text & "')"
Dim xcmd As New OdbcCommand(sSql, con)
If xcmd.ExecuteNonQuery() > 0 Then
'MessageBox.Show("ATTENDANCE SAVED")
txtrfid.Text = ""
'txtid.Text = ""
'txtfname.Text = ""
'txtlname.Text = ""
'txtposition.Text = ""
'txtsubject.Text = ""
txtrfid.Focus()
Dtagrid()
End If
If TextBox1.Text = "IN" Then
lblinuse.Visible = True
lblvacant.Visible = False
lbllstuser.Visible = False
lblcrrntuser.Visible = True
ElseIf TextBox1.Text = "OUT" Then
lblinuse.Visible = False
lblvacant.Visible = True
lbllstuser.Visible = True
lblcrrntuser.Visible = False
'txtid.Text = ""
'txtfname.Text = ""
'txtlname.Text = ""
'txtposition.Text = ""
'txtsubject.Text = ""
'imgRetrieve.Image = Nothing
End If
End If
Dtagrid()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
CAUSE
This error occurs only with Microsoft Access when one of the column
names specified in a select statement does not exist in the table
being queried.
Resolution
Remove any invalid column names from the select statement.
Make sure that Column Name RFID exist in Faculty table and also check txtrfid has value or not

How to edit/update records from the database using textbox by linq to sql?

I'm using visual basic 2008 express edition by linq to sql for my database operation such as edit records. I did not use any sql server but I'm just using the built-in sql server within the visual basic 2008 express. I tried to revised the codes, no error in syntax but there's an error at runtime and it pops-up a window message saying its error message. What I want is to edit the records which were retrieved from the database into the text-boxes and when you click the button5 whatever the new value on the text-boxes should replace the previous one.
The Account field is the field in my Table1 in memrec.dbml which I set up for primary key is true and the rest of the fields are false in its primary key.
The code below still found an error when you run the program and it pops-up a window which says:
NotSupportedException was unhandled - Sql server does not handle comparison of NText, Text, Xml, or Image data types.
It highlights a yellow background on the line:
db.SubmitChanges()
These are what I see on each field's property on Table1 in memrec.dbml property window:
Access - Public
Type - String(System.String)
Server Data Type - Text
Auto-Generated Value - False
Auto-Sync - Never
Delay Loaded - False
Inheritance Modifier - (none)
Nullable - True
Read Only - False
Time Stamp - False
Update Check - Never
Primary Key - False ' Except for the Account field.
What do you see as possible error?
Is it in terms of its settings?
Here's my codes:
Private Sub Button5_Click(------------------) Handles Button5.Click
If TextBox1.Text = "" Or TextBox2.Text = "" Or TextBox3.Text = "" Or _
TextBox4.Text = "" Then
MsgBox("Please Fill It Up Completely", MsgBoxStyle.Exclamation)
Exit Sub
Else
Dim accnt As String
accnt = TextBox1.Text
Dim db As New memrecDataContext()
Dim editrecord = _
From memrec In db.Table1s _
Where memrec.Account.Contains(accnt) _
Select memrec
For Each memrec In editrecord
If memrec.Account = accnt Then
memrec.Account = TextBox1.Text
memrec.Name = TextBox2.Text
memrec.Address = TextBox3.Text
memrec.Gender = TextBox4.Text
db.SubmitChanges()
Exit Sub
End If
Exit For
Next
MsgBox("No Records Match", MsgBoxStyle.Information)
End If
End Sub
Thank you for taking time with me to solve this issue.....
Where memrec.Account.Contains(accnt) _
This code will perform a "like" in your database and such action is not permited on NText and Text field.
Try changing your field type from Text to Varchar(500) (or bigger if you think 500 won't be enough)
or
If you intended to search for a known value, try changing you where to :
Where memrec.Account = accnt
Imports System.Data
Imports System.Data.SqlClient
Public Class frmRpro
Private Sub frmRpro_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
lock()
End Sub
Private Sub autonum()
Call main()
Con.Open()
Dim UserSelect As SqlCommand
Dim myreader As SqlDataReader
Dim sql As String
Dim sum As Integer
Dim no As Integer
'sql = "select * from packwell_customers where customer_code like '" & (txt1.Text) & "%'"
'sql.Max()
sql = "select max(rcv_reference) from DOrproduct"
UserSelect = New SqlCommand(sql, Con)
myreader = UserSelect.ExecuteReader
If (myreader.Read = True) Then
no = 1
txt1.Text = myreader(0)
sum = txt1.Text + no
txt1.Text = 0 & sum
clear()
End If
Con.Close()
End Sub
Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cnew.Click
If cnew.Text = "New" Then
cnew.Text = "Save"
cedit.Text = "Cancel"
clear()
autonum()
unlock()
cdel.Enabled = False
csearch.Enabled = False
txt1.Enabled = False
'Dim myDate As Date = Now
'txt3.Text = Format(myDate, "MM/dd/yyyy")
ElseIf txt1.Text = "" Or txt2.Text = "" Or txt3.Text = "" Or txt4.Text = "" Or txt5.Text = "" Or txt6.Text = "" Or txt7.Text = "" Or txt8.Text = "" Or txt9.Text = "" Or txt10.Text = "" Or txt11.Text = "" Or txt12.Text = "" Or txt13.Text = "" Or txt14.Text = "" Or txt15.Text = "" Or txt16.Text = "" Or txt17.Text = "" Or txt18.Text = "" Or txt19.Text = "" Or txt20.Text = "" Or txt21.Text = "" Or txt22.Text = "" Or txt23.Text = "" Or txt24.Text = "" Or txt25.Text = "" Or txt26.Text = "" Then
MsgBox("Incomplete data")
Else
cnew.Text = "Save"
cnew.Text = "New"
cedit.Text = "Update"
save()
clear()
lock()
cdel.Enabled = True
csearch.Enabled = True
End If
txt2.Focus()
End Sub
Private Sub save()
Call main()
Con.Open()
Dim adapter As New SqlDataAdapter
Dim sql As String
sql = "insert into DOrproduct (rcv_reference,customer,expected_date,date_arrived,time_arrived,customer_bol,reference,cust_order,releaseno,carrier,trailerno,issuedto,date_rcv,product,accounting,trader,lot,pkg,supply_rcv,status,opened_by,odate,arrivedby,adate,closeby,cdate) values('" & txt1.Text & "','" & txt2.Text & "', '" & txt3.Text & "', '" & txt4.Text & "', '" & txt5.Text & "', '" & txt6.Text & "', '" & txt7.Text & "', '" & txt8.Text & "', '" & txt9.Text & "', '" & txt10.Text & "', '" & txt11.Text & "', '" & txt12.Text & "', '" & txt13.Text & "', '" & txt14.Text & "', '" & txt15.Text & "', '" & txt16.Text & "', '" & txt17.Text & "', '" & txt18.Text & "', '" & txt19.Text & "', '" & txt20.Text & "', '" & txt21.Text & "', '" & txt22.Text & "', '" & txt23.Text & "', '" & txt24.Text & "', '" & txt25.Text & "', '" & txt26.Text & "')"
Try
adapter.InsertCommand = New SqlCommand(sql, Con)
adapter.InsertCommand.ExecuteNonQuery()
MsgBox("Row inserted !! ")
Catch ex As Exception
MsgBox(ex.ToString)
End Try
Con.Close()
End Sub
Private Sub clear()
'txt1.Text = ""
txt2.Text = ""
txt3.Text = ""
txt4.Text = ""
txt5.Text = ""
txt6.Text = ""
txt7.Text = ""
txt8.Text = ""
txt9.Text = ""
txt10.Text = ""
txt11.Text = ""
txt12.Text = ""
txt13.Text = ""
txt14.Text = ""
txt15.Text = ""
txt16.Text = ""
txt17.Text = ""
txt18.Text = ""
txt19.Text = ""
txt20.Text = ""
txt21.Text = ""
txt22.Text = ""
txt23.Text = ""
txt24.Text = ""
txt25.Text = ""
txt26.Text = ""
End Sub
Private Sub unlock()
txt1.Enabled = True
txt2.Enabled = True
txt3.Enabled = True
txt4.Enabled = True
txt5.Enabled = True
txt6.Enabled = True
txt7.Enabled = True
txt8.Enabled = True
txt9.Enabled = True
txt10.Enabled = True
txt11.Enabled = True
txt12.Enabled = True
txt13.Enabled = True
txt14.Enabled = True
txt15.Enabled = True
txt16.Enabled = True
txt17.Enabled = True
txt18.Enabled = True
txt19.Enabled = True
txt20.Enabled = True
txt21.Enabled = True
txt22.Enabled = True
txt23.Enabled = True
txt24.Enabled = True
txt25.Enabled = True
txt26.Enabled = True
End Sub
Private Sub lock()
txt1.Enabled = False
txt2.Enabled = False
txt3.Enabled = False
txt4.Enabled = False
txt5.Enabled = False
txt6.Enabled = False
txt7.Enabled = False
txt8.Enabled = False
txt9.Enabled = False
txt10.Enabled = False
txt11.Enabled = False
txt12.Enabled = False
txt13.Enabled = False
txt14.Enabled = False
txt15.Enabled = False
txt16.Enabled = False
txt17.Enabled = False
txt18.Enabled = False
txt19.Enabled = False
txt20.Enabled = False
txt21.Enabled = False
txt22.Enabled = False
txt23.Enabled = False
txt24.Enabled = False
txt25.Enabled = False
txt26.Enabled = False
End Sub
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
Dim frm As New frmRID
frm.Show()
frm.MdiParent = frmMain
Me.Hide()
End Sub
Private Sub locked()
txt1.Enabled = True
txt2.Enabled = True
End Sub
Private Sub unlocked()
txt1.Enabled = False
txt1.Enabled = False
End Sub
Private Sub cedit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cedit.Click
If cedit.Text = "Update" Then
If txt1.Text = "" Or txt2.Text = "" Or txt3.Text = "" Or txt4.Text = "" Or txt5.Text = "" Or txt6.Text = "" Or txt7.Text = "" Or txt8.Text = "" Or txt9.Text = "" Or txt10.Text = "" Or txt11.Text = "" Or txt12.Text = "" Or txt13.Text = "" Or txt14.Text = "" Or txt15.Text = "" Or txt16.Text = "" Or txt17.Text = "" Or txt18.Text = "" Or txt19.Text = "" Or txt20.Text = "" Or txt21.Text = "" Or txt22.Text = "" Or txt23.Text = "" Or txt24.Text = "" Or txt25.Text = "" Or txt26.Text = "" Then
MsgBox("you have no record to update please click command Search before update")
Else
updatesave()
csearch.Text = "Search"
clear()
lock()
End If
ElseIf cedit.Text = "Cancel" Then
cnew.Text = "New"
cedit.Text = "Update"
lock()
clear()
cdel.Enabled = True
csearch.Enabled = True
End If
End Sub
Private Sub updatesave()
Call main()
Con.Open()
Dim adapter As New SqlDataAdapter
Dim sql As String
sql = "update DOrproduct set rcv_reference ='" & txt1.Text & "', customer='" & txt2.Text & "', expected_date='" & txt3.Text & "', date_arrived='" & txt4.Text & "', time_arrived='" & txt5.Text & "', customer_bol='" & txt6.Text & "', reference='" & txt7.Text & "', cust_order='" & txt8.Text & "', releaseno='" & txt9.Text & "' ,carrier='" & txt10.Text & "' ,trailerno='" & txt11.Text & "' ,issuedto='" & txt12.Text & "' ,date_rcv='" & txt13.Text & "' ,product='" & txt14.Text & "' ,accounting='" & txt15.Text & "' ,trader='" & txt16.Text & "' ,lot='" & txt17.Text & "' ,pkg='" & txt18.Text & "' ,supply_rcv='" & txt19.Text & "' ,status='" & txt20.Text & "' ,opened_by='" & txt21.Text & "' ,odate='" & txt22.Text & "' ,arrivedby='" & txt23.Text & "' ,adate='" & txt24.Text & "' ,closeby='" & txt25.Text & "', cdate='" & txt26.Text & "' where rcv_reference ='" & txt1.Text & "'"
Try
adapter.UpdateCommand = Con.CreateCommand
adapter.UpdateCommand.CommandText = sql
adapter.UpdateCommand.ExecuteNonQuery()
MsgBox("records updated !! ")
Catch ex As Exception
MsgBox(ex.ToString)
End Try
Con.Close()
End Sub
Private Sub csearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles csearch.Click
unlock()
If csearch.Text = "Search" Then
csearch.Text = "Cancel"
cnew.Enabled = False
txt1.Focus()
ElseIf csearch.Text = "Cancel" Then
csearch.Text = "Search"
cnew.Enabled = True
clear()
lock()
End If
End Sub
Private Sub cdel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cdel.Click
On Error GoTo err
If cdel.Text = "Delete" Then
If txt1.Text = "" Or txt2.Text = "" Or txt3.Text = "" Or txt4.Text = "" Or txt5.Text = "" Or txt6.Text = "" Or txt7.Text = "" Or txt8.Text = "" Or txt9.Text = "" Or txt10.Text = "" Or txt11.Text = "" Or txt12.Text = "" Or txt13.Text = "" Or txt14.Text = "" Or txt15.Text = "" Or txt16.Text = "" Or txt17.Text = "" Or txt18.Text = "" Or txt19.Text = "" Or txt20.Text = "" Or txt21.Text = "" Or txt22.Text = "" Or txt23.Text = "" Or txt24.Text = "" Or txt25.Text = "" Or txt26.Text = "" Then
MsgBox("you have no record to Delete please click command Search before update")
Else : cdel.Text = "Delete"
Select Case MsgBox("Are you sure You want to Delete this Record", MsgBoxStyle.YesNo)
Case MsgBoxResult.Yes
deleterecord()
csearch.Text = "Search"
clear()
lock()
Case MsgBoxResult.No
GoTo err
End Select
End If
End If
err:
Exit Sub
End Sub
Private Sub deleterecord()
Call main()
Con.Open()
Dim adapter As New SqlDataAdapter
Dim sql As String
sql = "delete DOrproduct where rcv_reference ='" & txt1.Text & "'"
Try
adapter.DeleteCommand = Con.CreateCommand
adapter.DeleteCommand.CommandText = sql
adapter.DeleteCommand.ExecuteNonQuery()
MsgBox("Records deleted !! ")
Catch ex As Exception
MsgBox(ex.ToString)
End Try
Con.Close()
End Sub
Private Sub txt1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txt1.TextChanged
searchrcv_reference()
End Sub
Private Sub searchrcv_reference()
Call main()
Con.Open()
Dim cmd As New SqlCommand("SELECT rcv_reference FROM DOrproduct", Con)
Dim ds As New DataSet
Dim da As New SqlDataAdapter(cmd)
da.Fill(ds, "My List") 'list can be any name u want
Dim col As New AutoCompleteStringCollection
Dim i As Integer
For i = 0 To ds.Tables(0).Rows.Count - 1
col.Add(ds.Tables(0).Rows(i)("rcv_reference").ToString())
If txt1.Text = True Then
showsearch()
End If
Next
txt1.AutoCompleteSource = AutoCompleteSource.CustomSource
txt1.AutoCompleteCustomSource = col
txt1.AutoCompleteMode = AutoCompleteMode.Suggest
Con.Close()
End Sub
Private Sub showsearch()
Call main()
Con.Open()
Dim UserSelect As SqlCommand
Dim myreader As SqlDataReader
Dim sql As String
sql = "select * from DOrproduct where rcv_reference like '" & (txt1.Text) & "%'"
UserSelect = New SqlCommand(sql, Con)
myreader = UserSelect.ExecuteReader
If (myreader.Read = True) Then
'txt1.Text = myreader(0)
txt2.Text = myreader(1)
txt3.Text = myreader(2)
txt4.Text = myreader(3)
txt5.Text = myreader(4)
txt6.Text = myreader(5)
txt7.Text = myreader(6)
txt8.Text = myreader(7)
txt9.Text = myreader(8)
txt10.Text = myreader(9)
txt11.Text = myreader(10)
txt12.Text = myreader(11)
txt13.Text = myreader(12)
txt14.Text = myreader(13)
txt15.Text = myreader(14)
txt16.Text = myreader(15)
txt17.Text = myreader(16)
txt18.Text = myreader(17)
txt19.Text = myreader(18)
txt20.Text = myreader(19)
txt21.Text = myreader(20)
txt22.Text = myreader(21)
txt23.Text = myreader(22)
txt24.Text = myreader(23)
txt25.Text = myreader(24)
txt26.Text = myreader(25)
End If
Con.Close()
End Sub
Private Sub txt2_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txt2.TextChanged
showCustomer()
End Sub
Private Sub showCustomer()
Call main()
Con.Open()
Dim cmd As New SqlCommand("SELECT customer_name,customer_code FROM packwell_customers", Con)
Dim ds As New DataSet
Dim da As New SqlDataAdapter(cmd)
da.Fill(ds, "My List") 'list can be any name u want
Dim col2 As New AutoCompleteStringCollection
Dim i As Integer
For i = 0 To ds.Tables(0).Rows.Count - 1
col2.Add(ds.Tables(0).Rows(i)("customer_code").ToString())
col2.Add(ds.Tables(0).Rows(i)("customer_name").ToString())
Next
txt2.AutoCompleteSource = AutoCompleteSource.CustomSource
txt2.AutoCompleteCustomSource = col2
txt2.AutoCompleteMode = AutoCompleteMode.Suggest
Con.Close()
End Sub
End Class
The code is a little hard to read, but from what I could understand, it should work. You just need to put the SubmitChanges() method invocation outside the for loop.