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 6127359
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:29:51+00:00 2026-05-23T16:29:51+00:00

I have been learning from a tutorial on Home and Learn about setting up

  • 0

I have been learning from a tutorial on Home and Learn about setting up databases. Currently, I’m learning about finding records in a database. I’m trying to get my GO! button search for a ingredient in my data table, and I”ve followed the tutorial thoroughly and have no errors in my Error list, but this line of code:

returnRows = dataRecipe.Tables["CookBookRecipes"].Select("Ingredients = '" + searchOut + "'");

It stops my program, and brings up this message:

Object reference not set to an
instance of an object.

I’ve searched the meaning, and I guess it means my returnRows variable is null, but I can’t be sure. Can someone help me fix this problem?

Here is my full code in my Search button:

System.Data.SqlClient.SqlConnection con;
System.Data.SqlClient.SqlDataAdapter dataAdapt;
DataSet dataRecipe;

private void btnSearch_Click(object sender, EventArgs e)
{

    if (tbSearch.TextLength >= 1)
   {
        MessageBox.Show("This will work when you put it a word!");

        // Search code //

        string searchOut = tbSearch.Text;
        int result = 0;
        DataRow[] returnRows;

        returnRows = dataRecipe.Tables["CookBookRecipes"].Select("Ingredients = '" + searchOut + "'");


        result = returnRows.Length;

        if (result > 0)
        {
            DataRow rowBack;
            rowBack = returnRows[0];
            MessageBox.Show(rowBack[3].ToString());
        }
        else
        {
            MessageBox.Show("No such record");
        }

   }

   else
    {
       MessageBox.Show("Please enter an ingredient to search for!", "Search");
   }
}

Here is the full code of my form:

using System; 
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Cookbook {
    public partial class BrowseIngredients : Form {
       public BrowseIngredients() { InitializeComponent(); }
       private void exitToolStripMenuItem_Click(object sender, EventArgs e) {
           if (MessageBox.Show("Exit Cook Book?", "Exit?", MessageBoxButtons.OKCanc

I am very much a beginner, so forgive me if I don’t understand the real problem!

  • 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-05-23T16:29:52+00:00Added an answer on May 23, 2026 at 4:29 pm

    Looking at the tutorial you are using I think I can see where you have gone wrong (and I don’t blame you the – tutorial is not entirely clear).

    Based on this stage : http://www.homeandlearn.co.uk/csharp/csharp_s12p5.html

    You will have in your Form Load method a statement something like:

    string sql = "SELECT * From CookBookRecipes";
    dataAdapt = new System.Data.SqlClient.SqlDataAdapter(sql, con);
    

    However, the tutorial then tells you to add the following to get the data from the data adapter to into the dataset, but doesn’t actually show the code in context – and I suspect this is where you have gone wrong.

    Immediately after the above lines you need to add this:

    dataAdapt.Fill( dataRecipe, "CookBookRecipes" );
    

    Then when you attempt to get the rows from dataRecipe.Tables[“CookBookRecipes”] you will not be returning a reference to a null object.

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

Sidebar

Related Questions

I'm currently learning PHP and MySQL and I have been working from a basic
I have been learning C++ with some books from school that are from the
I come from classes object orientation languages and recently I have been learning those
I have been learning about the basics of C# but haven't come across a
I have been watching Xcode tutorials on youtube and learning from examples online but
I have been learning (slowly but surely) how to do deal with sqlite databases
I have been learning RESTful webservices following this tutorial http://www.vogella.de/articles/REST/article.html . As I understand,
I am learning rails by following the Rails Tutorial under Ubuntu. I have been
I have been learning OpenGL and SDL lately and I've become rather confused about
Hey I am very new to Web Programming. I have been learning PHP from

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.