Hi micah,
There may be records in database but the query you are firing is not returning records hence the error. Please verify the SQL Query and then run it in SQL Server.
You can handle this error by checking row count condition.
C#
protected void ddlCategory_SelectedIndexChanged(object sender, EventArgs e)
{
DataTable dt = GetDataTable("SELECT Quantity_Remaining FROM MainWareHouse WHERE Category = '" + ddlCategory.SelectedItem.Text.Trim() + "'");
Panel pn = (Panel)ddlCategory.FindControl("Panel2");
pn.Visible = true;
if (dt.Rows.Count > 0)
{
lblMessage2.Text = dt.Rows[0]["Quantity_Remaining"].ToString();
}
else
{
lblMessage2.Text = "No value found, please check again";
}
}
VB.Net
Protected Sub ddlCategory_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
Dim dt As DataTable = GetDataTable("SELECT Quantity_Remaining FROM MainWareHouse WHERE Category = '" & ddlCategory.SelectedItem.Text.Trim() & "'")
Dim pn As Panel = CType(ddlCategory.FindControl("Panel2"), Panel)
pn.Visible = True
If dt.Rows.Count > 0 Then
lblMessage2.Text = dt.Rows(0)("Quantity_Remaining").ToString()
Else
lblMessage2.Text = "No value found, please check again"
End If
End Sub