Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Nov 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Help with Query System

    I just started learning and using this program months ago.
    And now I sort of trying to make use of the knowledge I have by creating a simple query system.

    The system is about searching a data from the database and display the data.
    If a user checked a checkbox, it only searches and displays the specific data, but on to another page(from Search.aspx to Result.aspx)

    I have created the database, forms, etc.
    But I am kinda stuck with the checkbox and displaying the data.

    I wonder if any of you could help?
    I could attach the files needed if necessary and point out any procedures that missed.

  • #2
    New to the CF scene
    Join Date
    Nov 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    So basically, I have the database ready, the connection between the database and the web service has been made and the form is ready as well.

    This is my SearchPage.aspx.cs
    Code:
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Drawing;
    using System.Data;
    using System.Data.OleDb;
    using System.Web.Services;
    
    namespace QuerySystem
    {
    
        public partial class SearchPage : System.Web.UI.Page
        {
    
    
            protected void Page_Load(object sender, EventArgs e)
            {
    
            }
    
            protected void searchbtn_Click(object sender, EventArgs e)
            {
                string name = inputtxt.Text;
                errormsglbl.Text = "Hello " + name;
    
                if (name.Length == 0)
                {
                    errormsglbl.ForeColor = Color.Red;
                    errormsglbl.Text = "Please fill in the search box below";
                }
                else
                {
                    Response.Redirect("/ResultPage.aspx");
                }
    
            }
    
            protected void addbtn_Click(object sender, EventArgs e)
            {
                Response.Redirect("/AddPage.aspx");
            }
    
            protected void authorlbl_CheckedChanged(object sender, EventArgs e)
            {
    
            }
    
            protected void publisherlbl_CheckedChanged(object sender, EventArgs e)
            {
    
            }
    
            protected void titlecb_SelectedIndexChanged(object sender, EventArgs e)
            {
    
            }
        }
    }
    AddPage.aspx.cs
    Code:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Drawing;
    using System.Collections;
    
    namespace QuerySystem
    {
        public partial class AddPage : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
    
            }
    
            protected void TextBox1_TextChanged(object sender, EventArgs e)
            {
    
            }
    
            protected void cancelbtn_Click(object sender, EventArgs e)
            {
                Response.Redirect("/SearchPage.aspx");
            }
    
            protected void addbtn_Click(object sender, EventArgs e)
            {
                LibraryQueryReference.LibraryDatabase lquery = new LibraryQueryReference.LibraryDatabase();
    
                addtitle.Text = addtitle.Text.ToUpper();
                addauthor.Text = addauthor.Text.ToUpper();
                addpublisher.Text = addpublisher.Text.ToUpper();
    
                //This is for title
                if (addtitle.Text.Length == 0)
                {
                    errortitle.ForeColor = Color.Red;
                    errortitle.Text = "Please do not leave this blank";
                }
                else
                {
                    errortitle.Text = "";
                }
    
                // This is for author
                if (addauthor.Text.Length == 0)
                {
                    errorauthor.ForeColor = Color.Red;
                    errorauthor.Text = "Please do not leave this blank";
                }
                else
                {
                    errorauthor.Text = "";
                }
                
                // This is for publisher
                if (addpublisher.Text.Length == 0)
                {
                    errorpublisher.ForeColor = Color.Red;
                    errorpublisher.Text = "Please do not leave this blank";
                }
                else
                {
                    errorpublisher.Text = "";
                }
    
                //
                if (errortitle.Text.Equals("") && errorauthor.Text.Equals("") && errorpublisher.Text.Equals(""))
                {
                    lquery.addBook(addtitle.Text, addauthor.Text, addpublisher.Text);
                    Response.Redirect("/SearchPage.aspx");
                }
            }
    
            protected void addpublisher_TextChanged(object sender, EventArgs e)
            {
    
            }
        }
    }
    ResultPage.aspx.cs
    Code:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Data.OleDb;
    
    namespace QuerySystem
    {
        public partial class ResultPage : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
    
            }
    
            protected void backbtn_Click(object sender, EventArgs e)
            {
                Response.Redirect("/SearchPage.aspx");
            }
    
        }
    }
    DatabaseServices.asmx.cs
    Code:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.Services;
    using System.Data.OleDb;
    
    namespace QuerySystem
    {
        /// <summary>
        /// Summary description for Databases
        /// </summary>
        [WebService(Namespace = "http://tempuri.org/", Name="Library Database", Description="This is Database of the Library")]
        [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
        [System.ComponentModel.ToolboxItem(false)]
        // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
        // [System.Web.Script.Services.ScriptService]
        public class Databases : System.Web.Services.WebService
        {
            
            [WebMethod]
            public string CheckConnection()
            {
                    string result = "";
                    string connectionString =
                        "Provider=Microsoft.Jet.OLEDB.4.0;" +
                        "Data Source='C:\\Users\\Relzz Ak\\Documents\\Visual Studio 2012\\Projects\\LibraryQuerySystem\\QuerySystem\\App_data\\items.mdb';";
    
                using (OleDbConnection connection = new OleDbConnection(connectionString))
                {
                    try
                    {
                        connection.Open();
                        result = "Connection Success";
                    }
                    catch (Exception e)
                    {
                        result = "Error in Connection";
                    }
                }
                return result;
            }
    
            [WebMethod]
            public string addBook(String title, String author, String publisher)
            {
                string result = "";
    
                string connectionString =
                    "Provider=Microsoft.Jet.OLEDB.4.0;" +
                    "Data Source='C:\\Users\\Relzz Ak\\Documents\\Visual Studio 2012\\Projects\\LibraryQuerySystem\\QuerySystem\\App_data\\items.mdb';";
    
                string queryString = "INSERT INTO item_list VALUES ('" + title + "', '" + author + "', '" + publisher + "')";
    
                using (OleDbConnection connection = new OleDbConnection(connectionString))
                {
                    connection.Open();
                    OleDbCommand command = connection.CreateCommand();
                    command.CommandText = queryString;
                    // OleDbCommand command = new OleDbCommand(queryString, connection);
    
                    command.ExecuteNonQuery();
    
                    connection.Close();
    
                    result += "Item added";
                }
                return result;
            }
    
    
    
    
            [WebMethod]
            public string[] searchBook(string input, Boolean title, Boolean author, Boolean publisher)
            {
    
                string connectionString =
                    "Provider=Microsoft.Jet.OLEDB.4.0;" +
                    "Data Source='C:\\Users\\Relzz Ak\\Documents\\Visual Studio 2012\\Projects\\LibraryQuerySystem\\QuerySystem\\App_data\\items.mdb';";
    
                string queryString = "SELECT * FROM item_list WHERE Title = '" + input + "' OR Author = '" + input + "' OR Publisher = '" + input + "'";
    
                string lists = "";
    
                string[] book = new string[3];
    
                using (OleDbConnection connection = new OleDbConnection(connectionString))
                {
                    connection.Open();
                    OleDbCommand command = connection.CreateCommand();
                    command.CommandText = queryString;
    
                    OleDbDataReader reader = command.ExecuteReader();
    
                    while (reader.Read())
                    {
                        book[0] = reader[0].ToString();
                        book[1] = reader[1].ToString();
                        book[2] = reader[2].ToString();
                    }
    
                    if (title == true)
                    {
                        queryString = "SELECT * FROM item_list WHERE Title like '%" + input + "%'";
    
                        OleDbCommand comd2 = new OleDbCommand(queryString, connection);
                        comd2.CommandText = queryString;
                        OleDbDataReader read2 = comd2.ExecuteReader();
    
                        while (read2.Read())
                        {
                            lists += "<p> title = " + read2[0].ToString() + "<br> author = " + read2[1].ToString() + "<br> publisher = " + read2[2].ToString() + "</p>";
                        }
                    }
    
                    if (title == true)
                    {
                        queryString = "SELECT * FROM item_list WHERE Title LIKE '%" + input + "%'";
    
                        OleDbCommand comd3 = new OleDbCommand(queryString, connection);
                        comd3.CommandText = queryString;
                        OleDbDataReader read3 = comd3.ExecuteReader();
    
                        while (read3.Read())
                        {
                            lists += "<p> title = " + read3[0].ToString() + "<br> author = " + read3[1].ToString() + "<br> publisher = " + read3[2].ToString() + "</p>";
                        }
                    }
    
                    if (title == true)
                    {
                        queryString = "SELECT * FROM item_list WHERE Title LIKE '%" + input + "%'";
    
                        OleDbCommand comd4 = new OleDbCommand(queryString, connection);
                        comd4.CommandText = queryString;
                        OleDbDataReader read4 = comd4.ExecuteReader();
    
                        while (read4.Read())
                        {
                            lists += "<p> title = " + read4[0].ToString() + "<br> author = " + read4[1].ToString() + "<br> publisher = " + read4[2].ToString() + "</p>";
                        }
                    }
    
                    reader.Close();
                    connection.Close();
                }
                return book;
            }
        }
    }

    My problem is, how do I make the search button works and show the result in the result page?
    What should I do next?
    I could use some help and a tad explanations.
    Please & thanks.


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •