[C#, ASP.NET]If statement als database geen records vind

Pagina: 1
Acties:
  • 40 views sinds 30-01-2008

  • illstid
  • Registratie: Oktober 2005
  • Laatst online: 11-01-2024
Beste luitjes ik zit met het volgende probleem.

Ik heb een zoek functie gemaakt en deze werkt naar behoren. Echter nu wil ik dat er een error in een label verschijnt als je zoekt en de database can geen records vinden met de overeengekomen zoek opdracht. Het probleem dat ik nu heb is dat de error ten allen tijden verschijnt of hij nu wel of geen records vind.

Hieronder zal ik de design code en de source code plaatsen.

Alle hulp wordt zeer gewardeerd.

Design code

C#:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
public partial class UserControls_CustomerInformation : System.Web.UI.UserControl
{
    private int intCustomerSearch = -1;

    protected void Page_Load(object sender, EventArgs e)
    {

    }


    protected void btnSearch_Click(object sender, EventArgs e)
    {

        if (intCustomerSearch == 0)
        {
            lblError.Visible = true;
            CleanGUI();

        }

        else
        {
            string strConn = System.Configuration.ConfigurationManager.ConnectionStrings["BaseTicketSystemConnectionString"].ConnectionString;
            string strSqlString = "SELECT  DebtorNumber, DebtorName, DebtorAddress, DebtorTelephone from tblDebtor where DebtorNumber LIKE '%" + txtClientNumber.Text + "%'";
            SqlDataSource hatseklats = new SqlDataSource(strConn, strSqlString);
            hatseklats.ID = "stinkerd";
            Page.Controls.Add(hatseklats);

            GridView1.DataSourceID = hatseklats.ID;
            GridView1.DataBind();
            CleanGUI();
        }
    }

    public void CleanGUI()
    {
        txtClientNumber.Text = "";
    }

}


HTML Source code

HTML:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="CustomerInformation.ascx.cs" Inherits="UserControls_CustomerInformation" %>
&nbsp;<table style="width: 705px; height: 115px">
    <tr>
        <td style="width: 700px; height: 50px;">
                <asp:Label ID="lblSearchClient" runat="server" Text="Search a client!!!" Width="151px"></asp:Label></td>
    </tr>
    <tr>
        <td style="width: 700px; height: 1px;">
           
                <asp:Label ID="lblInsertCustomernumber" runat="server" Text="Insert Customer Number"></asp:Label>
                <asp:TextBox ID="txtClientNumber" runat="server" MaxLength="50" Width="170px"></asp:TextBox>
            <asp:RequiredFieldValidator ID="rfvCustomerNumber" runat="server" ControlToValidate="txtClientNumber"
                ErrorMessage="n00b!! You need to fill in something to find stuff!" Width="13px">*</asp:RequiredFieldValidator>
            &nbsp; &nbsp;&nbsp;<br />
            &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
            &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
            &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
            &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
        </td>
    </tr>
    <tr>
        <td style="width: 700px; height: 16px;">
                <asp:Button ID="btnSearch" runat="server" Text="Search!!"
                    Width="152px" OnClick="btnSearch_Click" />
            <asp:Label ID="lblError" runat="server" ForeColor="Red" Text="No Records Found!!"
                Visible="False" Width="162px"></asp:Label></td>
    </tr>
</table>
&nbsp;
<table style="width: 488px; height: 98px">
    <tr>
        <td style="height: 101px">
            <asp:ValidationSummary ID="ValidationSummary1" runat="server" />
        </td>
    </tr>
</table>
<asp:GridView ID="GridView1" runat="server" Width="488px" EnableTheming="True">
</asp:GridView>
<asp:SqlDataSource ID="ICT12" runat="server" ConnectionString="<%$ ConnectionStrings:BaseTicketSystemConnectionString %>">
</asp:SqlDataSource>

  • whoami
  • Registratie: December 2000
  • Laatst online: 14-02 20:35
Hoi,
wat jij moet doen, is debuggen. DAt is iets wat je als programmeur zelf moet kunnen. Je IDE biedt je daar ook een aantal faciliteiten voor (breakpoints, watches, ... ).

Ga bv eens na dmv debugging wat de waarde is van 'intCustomerSearch'. Ik zie nl. nergens deze variable opgevuld worden (bhalve bij initialisatie dan)

Het is iig niet de bedoeling om hier de hele lap code te posten, en dan te verwachten dat iemand anders het voor jou gaat uitspitten.
Maak ook gebruik van code-tags als je hier code wilt posten. :)

https://fgheysels.github.io/


Dit topic is gesloten.