ASP.NET problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Richard S
    New Member
    • Apr 2007
    • 9

    ASP.NET problem

    alright, first of all i love thise site, helped me out alot alreaddy, but now i have a problem witch i cant find a answer to after a LONG time of searching.

    I am trying to make a small search, witch will search true my database table called "serials" in the colum "SoftwareNa me" for a match. but im having the biggest trouble in making it work. this is my code atm:

    Code:
        protected void btn_search_Click(object sender, EventArgs e)
        {
    
            string search = box_searchfor.Text;
            
            string constring = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" + Server.MapPath("database.mdb");
            string SQLvraag = "SELECT * FROM serials WHERE SoftwareName= " + "box_searchfor.Text";
            OleDbConnection dbconnectie = new OleDbConnection(constring);
    
    
            // show the search results
            try
            {
                dbconnectie.Open();
                OleDbCommand cmd = new OleDbCommand(SQLvraag, dbconnectie);
                OleDbDataReader dr = cmd.ExecuteReader();
    
                lbl_result.Text = "";
    
                if (dr.HasRows)
                {
                    while (dr.Read())
                    {
                        lbl_result.Text += dr["SoftwareName"].ToString() + "<br /> ";
                    }
                }
                else
                {
                    lbl_result.Text = "Geen serial's gevonden.";
                }
    
            }
    
            catch (Exception ex)
            {
                lbl_result.Text = "Probleem met database" + "<br /><br />" + ex.ToString();
            }
    
            finally
            {
                dbconnectie.Close();
            }
        }
    and i am getting this error:

    Code:
    System.Data.OleDb.OleDbException: Waarden voor een of meer vereiste parameters ontbreken. at System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult) at System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult) at System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult) at System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method) at System.Data.OleDb.OleDbCommand.ExecuteReader(CommandBehavior behavior) at System.Data.OleDb.OleDbCommand.ExecuteReader() at _Default.btn_search_Click(Object sender, EventArgs e) in d:\Mijn Documenten\Visual Studio 2005\WebSites\Richards project\Seriallist.aspx.cs:line 80
    this is line 80:
    Code:
    OleDbDataReader dr = cmd.ExecuteReader();
    im desperate, that has nothing to do with my query! :S please help me out

    Richard S
  • prabunewindia
    New Member
    • Mar 2007
    • 199

    #2
    hi friend,
    i think the problem with ur query.
    SELECT * FROM serials WHERE SoftwareName= " + "box_searchfor. Text";

    try it

    SELECT * FROM serials WHERE SoftwareName= '" + box_searchfor.T ext+"'";
    just copy this and replace the old one and try


    Originally posted by Richard S
    alright, first of all i love thise site, helped me out alot alreaddy, but now i have a problem witch i cant find a answer to after a LONG time of searching.

    I am trying to make a small search, witch will search true my database table called "serials" in the colum "SoftwareNa me" for a match. but im having the biggest trouble in making it work. this is my code atm:

    Code:
        protected void btn_search_Click(object sender, EventArgs e)
        {
    
            string search = box_searchfor.Text;
            
            string constring = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" + Server.MapPath("database.mdb");
            string SQLvraag = "SELECT * FROM serials WHERE SoftwareName= " + "box_searchfor.Text";
            OleDbConnection dbconnectie = new OleDbConnection(constring);
    
    
            // show the search results
            try
            {
                dbconnectie.Open();
                OleDbCommand cmd = new OleDbCommand(SQLvraag, dbconnectie);
                OleDbDataReader dr = cmd.ExecuteReader();
    
                lbl_result.Text = "";
    
                if (dr.HasRows)
                {
                    while (dr.Read())
                    {
                        lbl_result.Text += dr["SoftwareName"].ToString() + "<br /> ";
                    }
                }
                else
                {
                    lbl_result.Text = "Geen serial's gevonden.";
                }
    
            }
    
            catch (Exception ex)
            {
                lbl_result.Text = "Probleem met database" + "<br /><br />" + ex.ToString();
            }
    
            finally
            {
                dbconnectie.Close();
            }
        }
    and i am getting this error:

    Code:
    System.Data.OleDb.OleDbException: Waarden voor een of meer vereiste parameters ontbreken. at System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult) at System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult) at System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult) at System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method) at System.Data.OleDb.OleDbCommand.ExecuteReader(CommandBehavior behavior) at System.Data.OleDb.OleDbCommand.ExecuteReader() at _Default.btn_search_Click(Object sender, EventArgs e) in d:\Mijn Documenten\Visual Studio 2005\WebSites\Richards project\Seriallist.aspx.cs:line 80
    this is line 80:
    Code:
    OleDbDataReader dr = cmd.ExecuteReader();
    im desperate, that has nothing to do with my query! :S please help me out

    Richard S

    Comment

    • Richard S
      New Member
      • Apr 2007
      • 9

      #3
      AWESOME! thanks man :D really helped (and it worked :P)

      but now i have the following thing, in my table i have a row with SoftwareName: Richard

      now if i search for R, it finds nothing, and if i search for Richard, it does. how do i fix this?

      i tried using this query:

      "SELECT * FROM serials WHERE SoftwareName= '" + "*" + box_searchfor.T ext + "*" + "'"

      but if i use that, it finds nothing, even when i search for Richard, wich is found with
      "SELECT * FROM serials WHERE SoftwareName= '" + box_searchfor.T ext + "'"

      Comment

      • gomzi
        Contributor
        • Mar 2007
        • 304

        #4
        Originally posted by Richard S
        AWESOME! thanks man :D really helped (and it worked :P)

        but now i have the following thing, in my table i have a row with SoftwareName: Richard

        now if i search for R, it finds nothing, and if i search for Richard, it does. how do i fix this?

        i tried using this query:

        "SELECT * FROM serials WHERE SoftwareName= '" + "*" + box_searchfor.T ext + "*" + "'"

        but if i use that, it finds nothing, even when i search for Richard, wich is found with
        "SELECT * FROM serials WHERE SoftwareName= '" + box_searchfor.T ext + "'"
        Try this,
        select * from serials where SoftwareName = "%" + '" + box_searchfor.T ext + "' + "%"

        Comment

        • Richard S
          New Member
          • Apr 2007
          • 9

          #5
          Originally posted by gomzi
          Try this,
          select * from serials where SoftwareName = "%" + '" + box_searchfor.T ext + "' + "%"

          "select * from serials where SoftwareName = " % " + '" + box_searchfor.T ext + "' + " % "";

          that gives me the following error:
          Operator '%' cannot be applied to operands of type 'string' and 'string'

          on 2 locations:

          "select * from serials where SoftwareName = "

          and on:

          "' + "

          :(

          Comment

          • Richard S
            New Member
            • Apr 2007
            • 9

            #6
            ups, sorry i did something wrong!

            i use this query now:
            "select * from serials where SoftwareName = "%" + '" + box_searchfor.T ext + "' + "%";

            witch gives me this error:
            Newline in constant (this is selected when i double click the error: ";)

            Comment

            • Richard S
              New Member
              • Apr 2007
              • 9

              #7
              alright, srry for tripple post guys, but i figured it out, and i thought id let you guys know how...

              Originally posted by gomzi
              Try this,
              select * from serials where SoftwareName = "%" + '" + box_searchfor.T ext + "' + "%"
              this is the query i came up with:

              Code:
              "select * from serials where SoftwareName LIKE '%" + search + "%'"
              the problem was that "SoftwareNa me =" should be "SoftwareNa me LIKE", LIKE helps you search for patterns :) so this fixed it!

              thanks for helping guys!

              Comment

              • gomzi
                Contributor
                • Mar 2007
                • 304

                #8
                Originally posted by Richard S
                alright, srry for tripple post guys, but i figured it out, and i thought id let you guys know how...



                this is the query i came up with:

                Code:
                "select * from serials where SoftwareName LIKE '%" + search + "%'"
                the problem was that "SoftwareNa me =" should be "SoftwareNa me LIKE", LIKE helps you search for patterns :) so this fixed it!

                thanks for helping guys!
                great!! sorry that i said = instead of like.

                Comment

                Working...