Hi there,
I am using a datarow to get data from my database and using a textbox to search for a part number, which if it finds it, will redirect to another page. This works fine, however if I enter an incorrect number it will come up with the error "index was outside the bounds of the array" even though I am using an if statement to say if it is empty.....
The code is below, any help would be greatly appreciated.
Imports System.Data.SqlClient
Imports System.Data
Partial Class About
Inherits System.Web.UI.Page
Public GetContent As DataTable
Public GetMB As DataRow
Public getBatteryContent As DataRow()
Public getM As DataTable
Protected Sub Page_load() Handles Me.Load
Dim sql As String() = {"SELECT * FROM Content"}
Dim tables As String() = {"Content"}
CheckTables(sql, tables)
GetContent = DataModule.GetContentSet.Tables("Content")
Page.DataBind()
End Sub
Public Function GetVis() As Boolean
Return System.IO.File.Exists(Server.MapPath(String.Format("/images/photography/{0}_back.jpg", Request.QueryString("type"))))
End Function
Protected Sub btnSearch_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtSearch.TextChanged
Dim sql As String() = {"SELECT * FROM Batteries"}
Dim tables As String() = {"Batteries"}
CheckTables(sql, tables)
Dim val As String = txtSearch.text
If isnumeric(txtSearch.text) = True Then
GetMB = GetContentSet.Tables("Batteries").Select("DinRef = " & val)(0)
If GetMB("id") = Nothing Then
lblStatus.Visible = True
Else
Response.Redirect(String.Format("/MBProduct.aspx?ref={0}", GetMB("id")))
Page.DataBind()
End If
Else
If val.Contains("-") Then
GetMB = GetContentSet.Tables("Batteries").Select("part = '" & val & "'")(0)
If GetMB("id") = Nothing Then
lblStatus.Visible = True
Else
Response.Redirect(String.Format("/MBProduct.aspx?ref={0}", GetMB("id")))
Page.DataBind()
End If
Else
GetMB = GetContentSet.Tables("Batteries").Select("WithoutHypons = '" & val & "'")(0)
If GetMB("id") = Nothing Then
lblStatus.Visible = True
Else
Response.Redirect(String.Format("/MBProduct.aspx?ref={0}", GetMB("id")))
Page.DataBind()
End If
End If
End If
'Response.Redirect(String.Format("/MBProduct.aspx?ref={0}", GetMB("id")))
'Page.DataBind()
End Sub
End Class