I've been gaining knowledge from a tutorial on Home and Find out about establishing databases. Presently, I am researching finding records inside a database. I am looking to get my GO! button look for a component during my data table, and that iInchng adopted the tutorial completely and also have no errors during my Error list, but this type of code:

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

It stops my program, and raises this message:

Object reference not set for an demonstration of an item.

I have looked this is, and that i guess this means my returnRows variable is null, however i can not be sure. Can someone assist me to fix this issue?

Here's my full code during 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");
   }
}

I'm greatly a novice, so forgive me basically do not understand the actual problem!

Thanks ahead of time, too.

Appears like you will possibly not be instantiating your computer data set. You declare it however, you aren't instantiating it, unless of course you're doing so elsewhere inside your code that you simply haven't proven us.

DataSet dataRecipe;

You can instatiate it within the page load event which could be fine.

private void Form_Load(object sender, EventArgs e)
{
    dataRecipe = new DataSet();
}

Searching in the tutorial you're using I believe I can tell in which you go wrong (and that i don't blame the - tutorial isn't entirely obvious).

According to this stage : http://www.homeandlearn.co.uk/csharp/csharp_s12p5.html

You'll have inside your Form Load method an argument something similar to:

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

However, the tutorial then informs you to definitely add the next to obtain the data in the data adapter to in to the dataset, but does not really show the code in context - and that i suspect this is when you've gone wrong.

Soon after the above mentioned lines you have to add this:

dataAdapt.Fill( dataRecipe, "CookBookRecipes" );

When you are trying to obtain the rows from dataRecipe.Tables["CookBookRecipes"] you won't be coming back a mention of the a null object.