How to use datagrid? - datagrid

I have inserted 4 columns (barcode, name, quantity and price).
When I scan any particular barcode for the 2nd time I don't want the data duplicated, just the quantity increased.
So far I have just coded
Private Sub CTbarcode_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
Main.MSAadodc1.Recordset.Find "BARCODE='" & CTbarcode.Text & "'", , adSearchForward, 1
If Not Main.MSAadodc1.Recordset.EOF Then
CAadodc1.Recordset.Find "BARCODE='" & CTbarcode.Text & "'", , adSearchForward, 1
If CAadodc1.Recordset.EOF Then
CTproduct.Text = Main.MSAadodc1.Recordset!PRODUCT
CTprice.Text = Main.MSAadodc1.Recordset!PRICE
CTquantity.Text = "1"
CAadodc1.Recordset.AddNew
CAadodc1.Recordset!tbarcode = CTbarcode.Text
CAadodc1.Recordset!tproduct = CTproduct.Text
CAadodc1.Recordset!tquantity = CTquantity.Text
CAadodc1.Recordset!tprice = CTprice.Text
CAadodc1.Recordset!tdiscount = CTquantity.Text
CAadodc1.Recordset!ttotalprice = Val(CTprice.Text * CTquantity.Text) - CTquantity.Text
CTbarcode.SetFocus
Else
CAadodc1.Recordset!tquantity = Val(CAadodc1.Recordset!tquantity + 1)
CTbarcode.SetFocus
CAadodc1.Refresh
End If
Else
MsgBox "Data Not Found!", vbOKOnly + vbCritical, "Unknown!"
CTbarcode.Text = ""
End If
End If
End Sub

Private Sub CTbarcode_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
Main.MSAadodc1.Recordset.Find "BARCODE='" & CTbarcode.Text & "'", , adSearchForward, 1
If Not Main.MSAadodc1.Recordset.EOF Then
CAadodc1.Recordset.Find "tbarcode='" & CTbarcode.Text & "'", , adSearchForward, 1
If CAadodc1.Recordset.EOF Then
CTproduct.Text = Main.MSAadodc1.Recordset!PRODUCT
CTprice.Text = Main.MSAadodc1.Recordset!PRICE
CTquantity.Text = "1"
CAadodc1.Recordset.AddNew
CAadodc1.Recordset!tbarcode = CTbarcode.Text
CAadodc1.Recordset!tproduct = CTproduct.Text
CAadodc1.Recordset!tquantity = CTquantity.Text
CAadodc1.Recordset!tprice = CTprice.Text
CAadodc1.Recordset!tdiscount = 0
CAadodc1.Recordset!ttotalprice = Val(CTprice.Text * CTquantity.Text) - CTquantity.Text
CTbarcode.SetFocus
CTbarcode.Text = ""
CTprice.Text = ""
CTproduct.Text = ""
CTquantity.Text = ""
Else
CAadodc1.Recordset!tquantity = CAadodc1.Recordset!tquantity + 1
CAadodc1.Recordset!tdiscount = 0
CAadodc1.Recordset!ttotalprice = Val(CAadodc1.Recordset!tprice * CAadodc1.Recordset!tquantity - CAadodc1.Recordset!tdiscount)
CAadodc1.Recordset.Update
CTbarcode.SetFocus
CTbarcode.Text = ""
CTprice.Text = ""
CTproduct.Text = ""
CTquantity.Text = ""
End If
Else
MsgBox "Data Not Found!", vbOKOnly + vbCritical, "Unknown!"
CTbarcode.Text = ""
End If
End If
End Sub

Related

I can't get selected value in drop down list for ddldialyser, after changing dropdown dependant on patient centre

aspx snippet
Dialyser: <asp:DropDownList runat="server" ID="ddlDialyser" AutoPostBack="true">
</asp:DropDownList>
<asp:RequiredFieldValidator ID="RFDialyser" runat="server" ErrorMessage="What dialyser does the patient use?" ControlToValidate="ddlDialyser" Display="None" ValidationGroup="valGroup1" EnableClientScript="false"></asp:RequiredFieldValidator>
code behind
Protected Sub BtnSearchPatHD_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles BtnSearchPatHD.Click
' dump data into controls
Dim pd As System.Data.DataSet
pd = Conn.dataSet("exec spr_searchPatientInfo '" & txtbxphdhno.Text & "'", "ruds")
lblHDPID.Text = pd.Tables(0).Rows(0).Item("PID")
lblHDFN.Text = pd.Tables(0).Rows(0).Item("Firstname")
lblHDSN.Text = pd.Tables(0).Rows(0).Item("Surname")
lblHDCons.Text = pd.Tables(0).Rows(0).Item("Cons")
lblHDCentre.Text = pd.Tables(0).Rows(0).Item("Centre")
' hd script elements
Dim hd As System.Data.DataSet
'concentrates
Dim concentrates As System.Data.DataSet
hd = Conn.dataSet("exec spr_searchPatientHDScript '" & lblHDPID.Text & "'", "ruds")
' change drop down list for dialysers and concentrates below depending on centre the patient belongs to
' dropdown menu changes
If lblHDCentre.Text = "JCUH" Or lblHDCentre.Text = "HOME" Then
' blank cell - list item
Dim liFirst As New System.Web.UI.WebControls.ListItem("", "")
' bind drop down list
Dim dialyser As Data.DataSet
dialyser = Conn.dataSet("select * from tbl_Dialysers WHERE Centre LIKE '%JCUH%' OR Centre LIKE '%HOME%'", "ruds")
ddlDialyser.DataValueField = "Dialyser"
ddlDialyser.DataTextField = "Dialyser"
ddlDialyser.DataSource = dialyser
ddlDialyser.DataBind()
ddlDialyser.Items.Insert(0, liFirst)
Dim concentrate As Data.DataSet
concentrate = Conn.dataSet("select * from tbl_Concentrates WHERE Centre LIKE '%JCUH%'", "ruds")
ddlConcentrate.DataValueField = "Concentrate"
ddlConcentrate.DataTextField = "Concentrate"
ddlConcentrate.DataSource = concentrate
ddlConcentrate.DataBind()
ddlConcentrate.Items.Insert(0, liFirst)
ElseIf lblHDCentre.Text = "NDC" Then
' blank cell - list item
Dim liFirst As New System.Web.UI.WebControls.ListItem("", "")
Dim dialyser As Data.DataSet
dialyser = Conn.dataSet("select * from tbl_Dialysers WHERE Centre LIKE '%NDC%'", "ruds")
ddlDialyser.DataValueField = "Dialyser"
ddlDialyser.DataTextField = "Dialyser"
ddlDialyser.DataSource = dialyser
ddlDialyser.DataBind()
ddlDialyser.Items.Insert(0, liFirst)
Dim concentrate As Data.DataSet
concentrate = Conn.dataSet("select * from tbl_Concentrates WHERE Centre LIKE '%NDC%'", "ruds")
ddlConcentrate.DataValueField = "Concentrate"
ddlConcentrate.DataTextField = "Concentrate"
ddlConcentrate.DataSource = concentrate
ddlConcentrate.DataBind()
ddlConcentrate.Items.Insert(0, liFirst)
ElseIf lblHDCentre.Text = "SDC" Then
' blank cell - list item
Dim liFirst As New System.Web.UI.WebControls.ListItem("", "")
Dim dialyser As Data.DataSet
dialyser = Conn.dataSet("select * from tbl_Dialysers WHERE Centre LIKE '%SDC%'", "ruds")
ddlDialyser.DataValueField = "Dialyser"
ddlDialyser.DataTextField = "Dialyser"
ddlDialyser.DataSource = dialyser
ddlDialyser.DataBind()
ddlDialyser.Items.Insert(0, liFirst)
Dim concentrate As Data.DataSet
concentrate = Conn.dataSet("select * from tbl_Concentrates WHERE Centre LIKE '%SDC%'", "ruds")
ddlConcentrate.DataValueField = "Concentrate"
ddlConcentrate.DataTextField = "Concentrate"
ddlConcentrate.DataSource = concentrate
ddlConcentrate.DataBind()
ddlConcentrate.Items.Insert(0, liFirst)
ElseIf lblHDCentre.Text = "DDC" Then
' blank cell - list item
Dim liFirst As New System.Web.UI.WebControls.ListItem("", "")
Dim dialyser As Data.DataSet
dialyser = Conn.dataSet("select * from tbl_Dialysers WHERE Centre LIKE '%DDC%'", "ruds")
ddlDialyser.DataValueField = "Dialyser"
ddlDialyser.DataTextField = "Dialyser"
ddlDialyser.DataSource = dialyser
ddlDialyser.DataBind()
ddlDialyser.Items.Insert(0, liFirst)
Dim concentrate As Data.DataSet
concentrate = Conn.dataSet("select * from tbl_Concentrates WHERE Centre LIKE '%DDC%'", "ruds")
ddlConcentrate.DataValueField = "Concentrate"
ddlConcentrate.DataTextField = "Concentrate"
ddlConcentrate.DataSource = concentrate
ddlConcentrate.DataBind()
ddlConcentrate.Items.Insert(0, liFirst)
ElseIf lblHDCentre.Text = "FDC" Then
' blank cell - list item
Dim liFirst As New System.Web.UI.WebControls.ListItem("", "")
Dim dialyser As Data.DataSet
dialyser = Conn.dataSet("select * from tbl_Dialysers WHERE Centre LIKE '%FDC%'", "ruds")
ddlDialyser.DataValueField = "Dialyser"
ddlDialyser.DataTextField = "Dialyser"
ddlDialyser.DataSource = dialyser
ddlDialyser.DataBind()
ddlDialyser.Items.Insert(0, liFirst)
Dim concentrate As Data.DataSet
concentrate = Conn.dataSet("select * from tbl_Concentrates WHERE Centre LIKE '%FDC%'", "ruds")
ddlConcentrate.DataValueField = "Concentrate"
ddlConcentrate.DataTextField = "Concentrate"
ddlConcentrate.DataSource = concentrate
ddlConcentrate.DataBind()
ddlConcentrate.Items.Insert(0, liFirst)
End If
If hd.Tables(0).Rows.Count > 0 Then
ddlDNAR.ClearSelection()
ddlDNAR.Items.FindByText(hd.Tables(0).Rows(0).Item("DNAR")).Selected = True
txtbxAllergies.Text = hd.Tables(0).Rows(0).Item("Allergies")
ddlTreat.ClearSelection()
ddlTreat.Items.FindByText(hd.Tables(0).Rows(0).Item("Treatment")).Selected = True
ddlTreat.SelectedItem.Text = hd.Tables(0).Rows(0).Item("Treatment")
Dim dialyser As String = hd.Tables(0).Rows(0).Item("Dialyser")
lblCurrentDialyser.Text = dialyser
' ddlDialyser.Items.FindByText(dialyser).Selected = True
If IsDBNull(hd.Tables(0).Rows(0).Item("Dialyser")) Then
ddlDialyser.ClearSelection()
Else
ddlDialyser.Items.FindByText(hd.Tables(0).Rows(0).Item("Dialyser")).Selected = True
End If
Dim dialysate As String = hd.Tables(0).Rows(0).Item("Concentrate")
lblCurrentConcentrate.Text = dialysate
If Not IsDBNull(hd.Tables(0).Rows(0).Item("Concentrate")) Then
If ddlConcentrate.SelectedItem.Text = dialysate Then
ddlConcentrate.SelectedValue = hd.Tables(0).Rows(0).Item("Concentrate")
concentrates = Conn.dataSet("exec spr_searchConcentrate '" & ddlConcentrate.SelectedValue & "'", "ruds")
lblNa.Text = concentrates.Tables(0).Rows(0).Item("Na")
lblCa.Text = concentrates.Tables(0).Rows(0).Item("Ca")
lblGlu.Text = concentrates.Tables(0).Rows(0).Item("Glu")
lblPo4.Text = concentrates.Tables(0).Rows(0).Item("p04")
Else
ddlConcentrate.SelectedValue = ""
End If
Else
ddlConcentrate.ClearSelection()
lblNa.Text = ""
lblCa.Text = ""
lblGlu.Text = ""
lblPo4.Text = ""
End If
Dim prd As String = hd.Tables(0).Rows(0).Item("PRD")
ddlPred.SelectedItem.Text = Conn.returnResult("select Diagnosis from tbl_RRPRD where PredID = '" & prd & "'", "Ruds")
ddlPred.SelectedValue = Conn.returnResult("select Code from tbl_RRPRD where PredID = '" & prd & "'", "Ruds")
ddlDiab.ClearSelection()
ddlDiab.Items.FindByText(hd.Tables(0).Rows(0).Item("Diab")).Selected = True
txtbxPDays.Text = hd.Tables(0).Rows(0).Item("Schedule")
txtbxHrs.Text = hd.Tables(0).Rows(0).Item("Duration")
txtbxDryW.Text = hd.Tables(0).Rows(0).Item("DryW")
ddlAccess.ClearSelection()
ddlAccess.Items.FindByText(hd.Tables(0).Rows(0).Item("Access")).Selected = True
ddlTinz.ClearSelection()
ddlTinz.Items.FindByText(hd.Tables(0).Rows(0).Item("Tinzaparin")).Selected = True
ddlTemp.SelectedValue = hd.Tables(0).Rows(0).Item("Temperature")
ddlInfect.ClearSelection()
ddlInfect.Items.FindByText(hd.Tables(0).Rows(0).Item("Infection")).Selected = True
ddlNeedle.SelectedValue = hd.Tables(0).Rows(0).Item("Needle")
ddlLinelock.SelectedValue = hd.Tables(0).Rows(0).Item("LineLock")
txtbxArtLumen.Text = hd.Tables(0).Rows(0).Item("ArtL")
txtbxVenLumen.Text = hd.Tables(0).Rows(0).Item("VenL")
ddlIronDosage.ClearSelection()
ddlIronDosage.Items.FindByText(hd.Tables(0).Rows(0).Item("IronDose")).Selected = True
ddlIronFrequency.SelectedValue = hd.Tables(0).Rows(0).Item("IronFreq")
ddlAranDosage.ClearSelection()
ddlAranDosage.Items.FindByText(hd.Tables(0).Rows(0).Item("AranDose")).Selected = True
ddlAranFrequency.SelectedValue = hd.Tables(0).Rows(0).Item("AranFreq")
txtbxComments.Text = hd.Tables(0).Rows(0).Item("Comments")
HFScriptDate.Value = hd.Tables(0).Rows(0).Item("ScriptDate")
Else
ddlDNAR.SelectedValue = ""
txtbxAllergies.Text = ""
ddlTreat.SelectedValue = ""
ddlDialyser.SelectedValue = ""
ddlConcentrate.SelectedValue = ""
ddlPred.SelectedValue = ""
ddlDiab.SelectedValue = ""
txtbxPDays.Text = ""
txtbxHrs.Text = ""
txtbxDryW.Text = ""
ddlAccess.SelectedValue = ""
ddlTinz.SelectedValue = ""
ddlTemp.SelectedValue = ""
ddlInfect.SelectedValue = ""
ddlNeedle.SelectedValue = ""
ddlLinelock.SelectedValue = ""
txtbxArtLumen.Text = ""
txtbxVenLumen.Text = ""
ddlIronDosage.SelectedValue = ""
ddlIronFrequency.SelectedValue = ""
ddlAranDosage.SelectedValue = ""
ddlAranFrequency.SelectedValue = ""
txtbxComments.Text = ""
HFScriptDate.Value = ""
End If
End Sub
I am having problem retrieving selected dialyser after changing dialyser drop down list dependant on patient centre, I want to ask how i can find selected value for dialyser.
this is the snippet i am having problems with below
If IsDBNull(hd.Tables(0).Rows(0).Item("Dialyser")) Then
ddlDialyser.ClearSelection()
Else
ddlDialyser.Items.FindByText(hd.Tables(0).Rows(0).Item("Dialyser")).Selected = True
End If

Argument 'expression' cannot be converted to type 'DBNull'

I have an app by vb for taking a list of doneators in Dvg and have about 17 forum and local mssql db and using if not is dbnull expression and by pressing the button some calculation happened and the answer appears in labels on the fourm.. But A strange problem happened when I run this app by the visual studio 2017 it run perfectly and there is no error.. But when converting it to exe file and setup it the following error appear when pressing this button " Argument 'expression' cannot be converted to type 'DBNull'
" although it's not appear when run it with visual studio.. What could the problem be..?
here is the code but i don't think the problem in it because it works fine in visual studio
its long code so i will put a part of it and the rest is repeated for 12 months and 10 yearsthis is pic of the error
If Form1.ComboBox1.Text = "2018" Then
' total kfalat
If TextBox1.Text = "1" Then
Form5.total.Text = Form1.Table1DataGridView.Rows.Count - 1
Dim HoN As Integer = 0
' total done
For Each gvRow As DataGridViewRow In Form2.TableDataGridView.Rows
If Not IsDBNull(gvRow.Cells(13).Value) Then
If Val(Me.TextBox2.Text) <= Val(gvRow.Cells(13).Value) AndAlso Val(gvRow.Cells(13).Value) <= Val(Me.TextBox3.Text) Then
If Not IsDBNull(gvRow.Cells(1).Value) Then
Dim strNgheo As String = gvRow.Cells(1).Value
If strNgheo = "1" Then
HoN = HoN + 1
End If
End If
End If
End If
Next
Form5.done.Text = HoN.ToString
'undone
Form5.notdone.Text = Val(Form5.total.Text) - Val(Form5.done.Text)
'asbab 3adam alta7seel
'lm yarod
Dim HoN11 As Integer = 0
For Each gvRow As DataGridViewRow In Form2.TableDataGridView.Rows
If Not IsDBNull(gvRow.Cells(13).Value) Then
If Val(Me.TextBox2.Text) <= Val(gvRow.Cells(13).Value) AndAlso Val(gvRow.Cells(13).Value) <= Val(Me.TextBox3.Text) Then
If Not IsDBNull(gvRow.Cells(1).Value) Then
Dim strNgheo As String = gvRow.Cells(1).Value
If strNgheo = "لم يرد" Then
HoN11 = HoN11 + 1
End If
End If
End If
End If
Next
Form5.Label69.Text = HoN11.ToString
'lmo2agal
Dim HoN12 As Integer = 0
For Each gvRow As DataGridViewRow In Form2.TableDataGridView.Rows
If Not IsDBNull(gvRow.Cells(13).Value) Then
If Val(Me.TextBox2.Text) <= Val(gvRow.Cells(13).Value) AndAlso Val(gvRow.Cells(13).Value) <= Val(Me.TextBox3.Text) Then
If Not IsDBNull(gvRow.Cells(1).Value) Then
Dim strNgheo As String = gvRow.Cells(1).Value
If strNgheo = "مؤجل" Then
HoN12 = HoN12 + 1
End If
End If
End If
End If
Next
Form5.Label67.Text = HoN12.ToString
'سيحضر
Dim HoN13 As Integer = 0
For Each gvRow As DataGridViewRow In Form2.TableDataGridView.Rows
If Not IsDBNull(gvRow.Cells(13).Value) Then
If Val(Me.TextBox2.Text) <= Val(gvRow.Cells(13).Value) AndAlso Val(gvRow.Cells(13).Value) <= Val(Me.TextBox3.Text) Then
If Not IsDBNull(gvRow.Cells(1).Value) Then
Dim strNgheo As String = gvRow.Cells(1).Value
If strNgheo = "سيحضر " Then
HoN13 = HoN13 + 1
End If
End If
End If
End If
Next
Form5.Label65.Text = HoN13.ToString
Dim HoN10 As Integer = 0
Dim money As Integer = 0
' astmarat gdeda
For Each gvRow As DataGridViewRow In Form1.Table1DataGridView.Rows
If Not IsDBNull(gvRow.Cells(8).Value) Then
If Val(Me.TextBox2.Text) <= Val(gvRow.Cells(8).Value) AndAlso Val(gvRow.Cells(8).Value) <= Val(Me.TextBox3.Text) Then
If Not IsDBNull(gvRow.Cells(15).Value) Then
'Dim strNgheo As Integer = gvRow.Cells(19).Value
' If strNgheo = (gvRow.Cells(19).Value = True) Then
If gvRow.Cells(15).Value > 0 Then
HoN10 = HoN10 + 1
' ElseIf gvRow.Cells(19).Value = False Then
' End
money = money + Val(gvRow.Cells(15).Value)
End If
End If
End If
End If
Next
Form5.Label59.Text = HoN10.ToString
Form5.Label58.Text = money.ToString
Dim orphensmoney1 As Integer = 0
Dim HoN1 As Integer = 0
Dim familiesmoney1 As Integer = 0
Dim HoN2 As Integer = 0
Dim sicksmoney1 As Integer = 0
Dim HoN3 As Integer = 0
Dim studentsmoney1 As Integer = 0
Dim HoN4 As Integer = 0
' alkafalat almotwagda belf3l
For Each gvRow As DataGridViewRow In Form1.Table1DataGridView.Rows
If Not IsDBNull(gvRow.Cells(19).Value) Then
'Dim strNgheo As Integer = gvRow.Cells(19).Value
' If strNgheo = (gvRow.Cells(19).Value = True) Then
If gvRow.Cells(19).Value = True Then
HoN1 = HoN1 + 1
' ElseIf gvRow.Cells(19).Value = False Then
' End
orphensmoney1 = orphensmoney1 + Val(gvRow.Cells(23).Value)
End If
End If
If Not IsDBNull(gvRow.Cells(20).Value) Then
'Dim strNgheo As Integer = gvRow.Cells(19).Value
' If strNgheo = (gvRow.Cells(19).Value = True) Then
If gvRow.Cells(20).Value = True Then
HoN2 = HoN2 + 1
' ElseIf gvRow.Cells(19).Value = False Then
' End
familiesmoney1 = familiesmoney1 + Val(gvRow.Cells(24).Value)
End If
End If
If Not IsDBNull(gvRow.Cells(21).Value) Then
'Dim strNgheo As Integer = gvRow.Cells(19).Value
' If strNgheo = (gvRow.Cells(19).Value = True) Then
If gvRow.Cells(21).Value = True Then
HoN3 = HoN3 + 1
' ElseIf gvRow.Cells(19).Value = False Then
' End
sicksmoney1 = sicksmoney1 + Val(gvRow.Cells(25).Value)
End If
End If
If Not IsDBNull(gvRow.Cells(22).Value) Then
'Dim strNgheo As Integer = gvRow.Cells(19).Value
' If strNgheo = (gvRow.Cells(19).Value = True) Then
If gvRow.Cells(22).Value = True Then
HoN4 = HoN4 + 1
' ElseIf gvRow.Cells(19).Value = False Then
' End
studentsmoney1 = studentsmoney1 + Val(gvRow.Cells(26).Value)
End If
End If
Next
Form5.Label11.Text = HoN1.ToString
Form5.Label10.Text = orphensmoney1.ToString
Form5.Label14.Text = HoN2.ToString
Form5.Label13.Text = familiesmoney1.ToString
Form5.Label17.Text = HoN3.ToString
Form5.Label16.Text = sicksmoney1.ToString
Form5.Label20.Text = HoN4.ToString
Form5.Label19.Text = studentsmoney1.ToString
Form5.Label8.Text = (Val(HoN1) + Val(HoN2) + Val(HoN3) + Val(HoN4)).ToString
Form5.Label9.Text = (Val(orphensmoney1) + Val(familiesmoney1) + Val(sicksmoney1) + Val(studentsmoney1)).ToString
Dim HoN5 As Integer = 0
Dim ORPHENS As Integer = 0
Dim HoN6 As Integer = 0
Dim families As Integer = 0
Dim HoN7 As Integer = 0
Dim sicks As Integer = 0
Dim HoN8 As Integer = 0
Dim students As Integer = 0
' almo7asal fe kol band
For Each gvRow As DataGridViewRow In Form2.TableDataGridView.Rows
If Not IsDBNull(gvRow.Cells(13).Value) Then
If Val(Me.TextBox2.Text) <= Val(gvRow.Cells(13).Value) AndAlso Val(gvRow.Cells(13).Value) <= Val(Me.TextBox3.Text) Then
If Not IsDBNull(gvRow.Cells(14).Value) Then
'Dim strNgheo As Integer = gvRow.Cells(19).Value
' If strNgheo = (gvRow.Cells(19).Value = True) Then
If gvRow.Cells(14).Value > 0 Then
HoN5 = HoN5 + 1
' ElseIf gvRow.Cells(19).Value = False Then
' End
ORPHENS = ORPHENS + Val(gvRow.Cells(14).Value)
End If
End If
If Not IsDBNull(gvRow.Cells(16).Value) Then
'Dim strNgheo As Integer = gvRow.Cells(19).Value
' If strNgheo = (gvRow.Cells(19).Value = True) Then
If gvRow.Cells(16).Value > 0 Then
HoN6 = HoN6 + 1
' ElseIf gvRow.Cells(19).Value = False Then
' End
families = families + Val(gvRow.Cells(16).Value)
End If
End If
If Not IsDBNull(gvRow.Cells(18).Value) Then
'Dim strNgheo As Integer = gvRow.Cells(19).Value
' If strNgheo = (gvRow.Cells(19).Value = True) Then
If gvRow.Cells(18).Value > 0 Then
HoN7 = HoN7 + 1
' ElseIf gvRow.Cells(19).Value = False Then
' End
sicks = sicks + Val(gvRow.Cells(18).Value)
End If
End If
If Not IsDBNull(gvRow.Cells(20).Value) Then
'Dim strNgheo As Integer = gvRow.Cells(19).Value
' If strNgheo = (gvRow.Cells(19).Value = True) Then
If gvRow.Cells(20).Value > 0 Then
HoN8 = HoN8 + 1
' ElseIf gvRow.Cells(19).Value = False Then
' End
students = students + Val(gvRow.Cells(20).Value)
End If
End If
End If
End If
Next
Form5.Label32.Text = HoN5.ToString
Form5.Label31.Text = ORPHENS.ToString
Form5.Label29.Text = HoN6.ToString
Form5.Label28.Text = families.ToString
Form5.Label26.Text = HoN7.ToString
Form5.Label25.Text = sicks.ToString
Form5.Label23.Text = HoN8.ToString
Form5.Label22.Text = students.ToString
Form5.Label35.Text = Val(HoN8.ToString) + Val(HoN7.ToString) + Val(HoN6.ToString) + Val(HoN5.ToString)
Form5.Label34.Text = Val(ORPHENS.ToString) + Val(families.ToString) + Val(sicks.ToString) + Val(students.ToString)
Form5.Label53.Text = Val(Form5.Label8.Text) - Val(Form5.Label35.Text)
Form5.Label52.Text = Val(Form5.Label9.Text) - Val(Form5.Label34.Text)
Form5.Label50.Text = Val(Form5.Label11.Text) - Val(Form5.Label32.Text)
Form5.Label49.Text = Val(Form5.Label10.Text) - Val(Form5.Label31.Text)
Form5.Label47.Text = Val(Form5.Label14.Text) - Val(Form5.Label29.Text)
Form5.Label46.Text = Val(Form5.Label13.Text) - Val(Form5.Label28.Text)
Form5.Label44.Text = Val(Form5.Label17.Text) - Val(Form5.Label26.Text)
Form5.Label43.Text = Val(Form5.Label16.Text) - Val(Form5.Label25.Text)
Form5.Label41.Text = Val(Form5.Label20.Text) - Val(Form5.Label23.Text)
Form5.Label40.Text = Val(Form5.Label19.Text) - Val(Form5.Label22.Text)
End If

run-time error '5' maps.googleapis.com/maps/api/distancematrix

Yesterday, I ran the following script in excel and it worked, but now it throws an error:
(run-time error '5' )
in the line:
Distance = Mid(Distance, InStr(1, Distance, ">") + 1, InStr(1, Distance, " ") - InStr(1, Distance, ">") - 1)
Sub Поиск_ближайшего_СБС()
Set Points = Worksheets("Точки")
Set SBS = Worksheets("СБС")
Dim Cordinate11, Cordinate12, Cordinate21, Cordinate22 As String
i = 2
Do While SBS.Cells(i, 1) <> Empty
Rows_of_SBS = i
i = i + 1
Loop
i = 2
Do While Cells(i, 1) <> Empty
Dist = 1000
Cordinate21 = Points.Cells(i + 1, 3)
Cordinate22 = Points.Cells(i + 1, 4)
For j = 2 To Rows_of_SBS
Cordinate11 = SBS.Cells(j, 2)
Cordinate12 = SBS.Cells(j, 3)
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = False
With IE
.Navigate "http://maps.googleapis.com/maps/api/distancematrix/xml?origins=" _
& Cordinate11 & ",+" & Cordinate12 _
& "&destinations=" _
& Cordinate21 & ",+" & Cordinate22 _
& "&mode=driving&language=ru&sensor=false"
Do While .Busy
DoEvents
Loop
For Each MyTable In .Document.getElementsByTagName("text")
Distance = MyTable.innertext
Next
Distance = Mid(Distance, InStr(1, Distance, ">") + 1, InStr(1, Distance, " ") - InStr(1, Distance, ">") - 1)
If CDbl(Distance) < Dist Then
Dist = CDbl(Distance) s = j
End If
End With
IE.Quit
Set EI = Nothing
Next j
Points.Cells(i + 1, 5) = Dist
Points.Cells(i + 1, 6) = SBS.Cells(s, 1)
i = i + 1
Loop
End Sub
'

Clear Form Button is not working correctly

Created a master.page and added several content pages. Imported the code from previous webform into one of my content pages. Now the clear button is not working correctly. It will not clear the textboxes or checkboxes. greatly appreciate any help. The form worked perfectly as a standalone page.
vb code:
Partial Class _Default
Inherits System.Web.UI.Page
Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim Num1, Num2, Num3, Num4 As Double
Dim Opt1, Opt2, Opt3, Opt4 As Double
Dim BaseTotal, OptionTotal, GrandTotal, Tax As Double
Num1 = Val(TextBox1.Text) * 1500
Num2 = Val(TextBox2.Text) * 70
Num3 = Val(TextBox3.Text) * 90
Num4 = Val(TextBox4.Text) * 130
If CheckBox1.Checked Then
Opt1 = 175
End If
If CheckBox2.Checked Then
Opt2 = 400
End If
If CheckBox3.Checked Then
Opt3 = 100
End If
If CheckBox4.Checked Then
Opt4 = 200
End If
' sum of checkboxes
OptionTotal = Opt1 + Opt2 + Opt3 + Opt4
'total base options
BaseTotal = Num1 + Num2 + Num3 + Num4
' Tax calculation
Tax = (OptionTotal + BaseTotal) * 0.095
GrandTotal = (BaseTotal + OptionTotal + Tax)
'output to text boxes
TextBox5.Text = FormatNumber(BaseTotal, 2)
TextBox6.Text = FormatNumber(OptionTotal, 2)
TextBox7.Text = FormatNumber(Tax, 2)
TextBox8.Text = FormatNumber(GrandTotal, 2)
End Sub
For Each ctrl As Control In form1.Controls
If ctrl.[GetType]() = GetType(TextBox) Then
DirectCast(ctrl, TextBox).Text = String.Empty
ElseIf ctrl.[GetType]() = GetType(CheckBox) Then
DirectCast(ctrl, CheckBox).Checked = False
End If
Next
***************If I use the following code of course it works, however it would be tedious if there were numerous controls on the page.
Protected Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
TextBox4.Text = ""
TextBox5.Text = ""
TextBox6.Text = ""
TextBox7.Text = ""
TextBox8.Text = ""
CheckBox1.Checked = False
CheckBox2.Checked = False
CheckBox3.Checked = False
CheckBox4.Checked = False
End Sub

VB.Net GridView Table with paging, on PageIndexChanging event displays nothing or first page again

I am trying to display data queried from Oracle in a grid view and have added paging with a PageIndexChanging event. However, after a few different tries with small changes, clicking another page either displays screen with no grid view or just refreshes site with gridview still on page 1. Never worked with web apps/sites before, any ideas?
Code:
Imports System.Data
Partial Class _Default
Inherits System.Web.UI.Page
Protected Sub Search_Click(sender As Object, e As EventArgs) Handles Search.Click
Dim con As OleDb.OleDbConnection
Dim command As OleDb.OleDbCommand
Dim commandstr As String
Dim wherestr As String
Dim dt As DataTable = New DataTable
Dim oda As OleDb.OleDbDataAdapter = New OleDb.OleDbDataAdapter
'Remove any non-aplhanumeric characters from the input string
MeterID_tb.Text = Regex.Replace(MeterID_tb.Text, "[^A-Za-z0-9]+", "")
'Opco_tb.Text = Regex.Replace(Opco_tb.Text, "[^A-Za-z0-9]+", "")
DateFrom_tb.Text = Regex.Replace(DateFrom_tb.Text, "[^A-Za-z0-9]+", "")
DateTo_tb.Text = Regex.Replace(DateTo_tb.Text, "[^A-Za-z0-9]+", "")
'Don't allow the user to search without a filter. The results returned will be too large
'Opco_tb.Text = "" &
If (MeterID_tb.Text = "") And (Division_db.SelectedValue = "Any") And (DateFrom_tb.Text = "") And (DateTo_tb.Text = "") Then
Dim strScript As String = "<script language=JavaScript>"
strScript += "alert(""" & "You must enter at least one search parameter." & """);"
strScript += "</script>"
If (Not Page.IsStartupScriptRegistered("clientScript")) Then
Page.RegisterStartupScript("clientScript", strScript)
End If
Exit Sub
End If
con = New OleDb.OleDbConnection(*Hidden*)
commandstr = "SELECT METERID as ""Meter ID"", REPID as ""Rep ID"", DIVISION as ""Division"", CITY as ""City"", ADDRESS as ""Address"", RATECODE as ""Ratecode"", METERFORM as ""Meter Form"", METERSTATUS as ""Meter Status"", METERPOINTSTATUS as ""Meter Point Status"", BILLINGCYCLE as ""Billing Cycle"", FILENAME as ""Filename"", FILEDATETIME as ""File Date/Time"" from BAD_METER_LIST"
wherestr = " WHERE"
If MeterID_tb.Text <> "" Then
If wherestr = " WHERE" Then
wherestr = wherestr + " METERID = '" + MeterID_tb.Text + "'"
Else
wherestr = wherestr + " AND METERID = '" + MeterID_tb.Text + "'"
End If
End If
If Division_db.SelectedValue <> "Any" Then
If wherestr = " WHERE" Then
wherestr = wherestr + " DIVISION = " + Division_db.SelectedValue
Else
wherestr = wherestr + " AND DIVISION = " + Division_db.SelectedValue
End If
End If
If DateFrom_tb.Text <> "" Then
If wherestr = " WHERE" Then
wherestr = wherestr + " FILEDATETIME >= to_date('" & DateFrom_tb.Text & "', 'mmddyyyy')"
Else
wherestr = wherestr + " AND FILEDATETIME >= to_date('" & DateFrom_tb.Text & "', 'mmddyyyy')"
End If
End If
If DateTo_tb.Text <> "" Then
If wherestr = " WHERE" Then
wherestr = wherestr + " FILEDATETIME <= to_date('" & DateTo_tb.Text & "', 'mmddyyyy')"
Else
wherestr = wherestr + " AND FILEDATETIME <= to_date('" & DateTo_tb.Text & "', 'mmddyyyy')"
End If
End If
command = New OleDb.OleDbCommand(commandstr + wherestr)
command.Connection = con
con.Open()
oda.SelectCommand = command
oda.Fill(dt)
Me.Grid_Bad_Meters.DataSource = dt
Me.Grid_Bad_Meters.DataBind()
End Sub
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
End Sub
Protected Sub Grid_Bad_Meters_PageIndexChanging(sender As Object, e As GridViewPageEventArgs) Handles Grid_Bad_Meters.PageIndexChanging
'Grid_Bad_Meters.Visible = True
Grid_Bad_Meters.PageIndex = e.NewPageIndex
Grid_Bad_Meters.DataBind()
End Sub
End Class
You need to rebind the GridView upon changing PageIndex.
Imports System.Data
Partial Class _Default
Inherits System.Web.UI.Page
#Region "Subs"
Private Sub CleanInput()
'Remove any non-aplhanumeric characters from the input string
MeterID_tb.Text = Regex.Replace(MeterID_tb.Text, "[^A-Za-z0-9]+", "")
'Opco_tb.Text = Regex.Replace(Opco_tb.Text, "[^A-Za-z0-9]+", "")
DateFrom_tb.Text = Regex.Replace(DateFrom_tb.Text, "[^A-Za-z0-9]+", "")
DateTo_tb.Text = Regex.Replace(DateTo_tb.Text, "[^A-Za-z0-9]+", "")
End Sub
Private Sub RequireFilter
'Don't allow the user to search without a filter. The results returned will be too large
'Opco_tb.Text = "" &
If ((MeterID_tb.Text = "")
AndAlso (Division_db.SelectedValue = "Any")
AndAlso (DateFrom_tb.Text = "")
AndAlso (DateTo_tb.Text = "")) Then
Dim strScript As String = "<script language=JavaScript>"
strScript += "alert(""" & "You must enter at least one search parameter." & """);"
strScript += "</script>"
If (Not Page.IsStartupScriptRegistered("clientScript")) Then
Page.RegisterStartupScript("clientScript", strScript)
End If
Exit Sub
End If
End Sub
Private Sub FillGridView
Dim con As OleDb.OleDbConnection
Dim command As OleDb.OleDbCommand
Dim commandstr As String
Dim wherestr As String
Dim dt As DataTable = New DataTable
Dim oda As OleDb.OleDbDataAdapter = New OleDb.OleDbDataAdapter
con = New OleDb.OleDbConnection(*Hidden*)
commandstr = "SELECT METERID as ""Meter ID"", REPID as ""Rep ID"", DIVISION as ""Division"", CITY as ""City"", ADDRESS as ""Address"", RATECODE as ""Ratecode"", METERFORM as ""Meter Form"", METERSTATUS as ""Meter Status"", METERPOINTSTATUS as ""Meter Point Status"", BILLINGCYCLE as ""Billing Cycle"", FILENAME as ""Filename"", FILEDATETIME as ""File Date/Time"" from BAD_METER_LIST"
wherestr = " WHERE"
If MeterID_tb.Text <> "" Then
If wherestr = " WHERE" Then
wherestr = wherestr + " METERID = '" + MeterID_tb.Text + "'"
Else
wherestr = wherestr + " AND METERID = '" + MeterID_tb.Text + "'"
End If
End If
If Division_db.SelectedValue <> "Any" Then
If wherestr = " WHERE" Then
wherestr = wherestr + " DIVISION = " + Division_db.SelectedValue
Else
wherestr = wherestr + " AND DIVISION = " + Division_db.SelectedValue
End If
End If
If DateFrom_tb.Text <> "" Then
If wherestr = " WHERE" Then
wherestr = wherestr + " FILEDATETIME >= to_date('" & DateFrom_tb.Text & "', 'mmddyyyy')"
Else
wherestr = wherestr + " AND FILEDATETIME >= to_date('" & DateFrom_tb.Text & "', 'mmddyyyy')"
End If
End If
If DateTo_tb.Text <> "" Then
If wherestr = " WHERE" Then
wherestr = wherestr + " FILEDATETIME <= to_date('" & DateTo_tb.Text & "', 'mmddyyyy')"
Else
wherestr = wherestr + " AND FILEDATETIME <= to_date('" & DateTo_tb.Text & "', 'mmddyyyy')"
End If
End If
command = New OleDb.OleDbCommand(commandstr + wherestr)
command.Connection = con
con.Open()
oda.SelectCommand = command
oda.Fill(dt)
Me.Grid_Bad_Meters.DataSource = dt
Me.Grid_Bad_Meters.DataBind()
End Sub
#End Region
Protected Sub Search_Click(sender As Object, e As EventArgs) Handles Search.Click
CleanInput()
RequireFilter()
FillGridView()
End Sub
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
End Sub
Protected Sub Grid_Bad_Meters_PageIndexChanging(sender As Object, e As GridViewPageEventArgs) Handles Grid_Bad_Meters.PageIndexChanging
'Grid_Bad_Meters.Visible = True
Grid_Bad_Meters.PageIndex = e.NewPageIndex
Grid_Bad_Meters.DataBind()
FillGridView()
End Sub
End Class

Resources