1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Help query search in database C#

Discussion in 'C, C++, C#' started by AmHasch, Nov 14, 2013.

  1. AmHasch

    AmHasch Newbie

    Joined:
    Nov 14, 2013
    Messages:
    1
    Likes Received:
    0
    Hi although it has been sometime that i learn C# but i still considered my self a newbie.

    I am trying to make a library system but right now i want to focus on my web services in searching terms inside my database.

    Code:
            public ArrayList searchBook(String input, Boolean title, Boolean author, Boolean publisher)
            {
                string result = "";
    
    
                string connectionString =
                    "Provider=Microsoft.Jet.OLEDB.4.0;" +
                    "Data Source=' *i purposely deleted this* Lib_item.mdb';";
    
    
                ArrayList book = new ArrayList();
    
    
                using (OleDbConnection connection = new OleDbConnection(connectionString))
                {
                    connection.Open();
                    OleDbCommand command = connection.CreateCommand();
                    command.CommandText = queryString;
    
    
                    OleDbDataReader reader = command.ExecuteReader();
    
    
                    while (reader.Read())
                    {
                        book.Add(reader[0].ToString());
                    }
                    reader.Close();
                    connection.Close();
    
    
                }
                return book;
            }
    
    
    
    I simply followed a tutorial i got and implemented it on my project but failed to load. The only thing i know, the program i used told me that "queryString" is wrong, i mean with red underline.

    can anyone point out what i did wrong here?
     
  2. neutralhatter

    neutralhatter Jr. VIP Jr. VIP Premium Member

    Joined:
    Jun 23, 2010
    Messages:
    430
    Likes Received:
    330
    you have to declare queryString first and then put a query in it.

    string queryString = "select * from sometable";