Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8848357
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T12:24:20+00:00 2026-06-14T12:24:20+00:00

I’m working on a relatively straight forward C# project that connects an Access Database

  • 0

I’m working on a relatively straight forward C# project that connects an Access Database via OleDb with various functions such as adding, deleting and editing records. Now, everything has worked fine up until trying to implement a database search.

The following line (in the searchbox code) throws up the exception during debug, but I am unsure what is actually a null value that is causing it to break.

ReturnedResults = DBDataSet.Tables["Movies"].Select("Title like '%" + Search + "%'");

So the goal is to search through the ‘Movies’ table in the database and find movies based on the user’s input (stored in the ‘Search’ string).

The search box’s code can be found below, and the database initialisation and connection is provided at the bottom.

private void SearchTextBox_Changed(object sender, EventArgs e)
{
  string SearchString = SearchTextBox.Text.ToString();
  int Results = 0;
  DataRow[] ReturnedResults;

  ReturnedResults = DataSet.Tables["Movies"].Select("Title like '%" + SearchString + "%'");
  Results = ReturnedResults.Length;

  if (Results > 0)
 {
    SearchResultsBox.Items.Clear();
    for (int i = 0; i <= Results; i++)
    {
      DataRow Row;
      Row = ReturnedResults[i];
      SearchResultsBox.Items.Add(Row["Title"].ToString());
    }
 }
  else
 {
   SearchResultsBox.Items.Clear();
   MessageBox.Show("Error! No items found.");
 }
}

For some context here is the main database initialisation/connection and the form load events:

public partial class BaseForm : Form
{
  System.Data.OleDb.OleDbConnection Connection;

  DataSet DataSet;

  System.Data.OleDb.OleDbDataAdapter DataAdapter;

  int MaxRows = 0;
  int CurrentRow = 0;

public BaseForm()
{
  InitializeComponent();
}

private void BaseForm_Load(object sender, EventArgs e)
{
  Connection = new System.Data.OleDb.OleDbConnection();
  Connection.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;DataSource=Movies.accdb";
  Connection.Open();

  DataSet = new DataSet();

  string sq1 = "SELECT * From Movies";
  DataAdapter = new System.Data.OleDb.OleDbDataAdapter(sq1, DBConnection);
  DataAdapter.Fill(DBDataSet);

  MaxRows = DataSet.Tables[0].Rows.Count;
  DisplayRecord();
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T12:24:21+00:00Added an answer on June 14, 2026 at 12:24 pm

    Multiple things can be null in your statement. DBDataSet can be null, or the table Movies doesn’t exits. You may add following check before the line.

    if(DBDataSet != null && 
       DBDataSet.Tables.Count > 0 && 
       DBDataSet.Tables["Movies"] != null)
    {
        ReturnedResults = DBDataSet.Tables["Movies"].Select("Title like '%" + Search + "%'");
        //....  rest of your code
    

    You may also try accessing the record against Tables[0] instead of Table Movies

    EDIT:

    For your next problem, mentioned in the comment, your for loop is executing till the length. It should be like:

    for (int i = 0; i < Results; i++) // Less than (<) not less than equal to 
        {
          DataRow Row;
          Row = ReturnedResults[i];
          SearchResultsBox.Items.Add(Row["Title"].ToString());
        }
    

    You need to modify the condition and remember the index starts from 0 and you will get rows till Result - 1

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
Let's say I'm outputting a post title and in our database, it's Hello Y&#8217;all
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I've got a string that has curly quotes in it. I'd like to replace
I have a small JavaScript validation script that validates inputs based on Regex. I
I have a French site that I want to parse, but am running into
I am doing a simple coin flipping experiment for class that involves flipping a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.