I have looked through the forum for this information. But I did not find anything I could use in my little program.

I have this read code:

----------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.OleDb;

namespace AddressBook
{
    class Program
    {
        static void Main(string[] args)
        {
            //Opret forbindelse til databasen.
            OleDbConnection oleConnection = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=adresse_opslag.mdb");
            //Opret objekt og sql søgning.
            OleDbCommand oleCommand = new OleDbCommand("SELECT * FROM adresse_opslag", oleConnection);
            
            try
            {
                //Åben database forbindelsen
                oleConnection.Open();
                //Opret "Datareader" som skal læse i tabelen.
                OleDbDataReader oleDataReader = oleCommand.ExecuteReader();

                //"While loop" som skal søge hele data tabelen igennem.
                //"Console" som skal byttes ud med Windowsform!.
                while (oleDataReader.Read())
                {
                    // Søge funktionen "Søgeord"
                    if (oleDataReader.GetString(0) == "John")
                    {
                        Console.WriteLine(oleDataReader.GetString(0) + "\t" + oleDataReader.GetString(1) + "\t" + oleDataReader.GetString(2) + "\t" + oleDataReader.GetString(3));
                    }
                }

                //Luk forbindelsen.
                oleConnection.Close();
                //Hold console åben. Denne linje skal bare slettes.
                Console.Read();
            }

            //Visning af fejl hvis den opstår.
            catch (OleDbException ex)
            {
                Console.WriteLine(ex.Message);
                Console.Read();
            }
        }
    }
}

------------------------------------------------------------------

Now I need two codes to do the following:

Look through the entry “if (oleDataReader.GetString(0) == "John")” and if there is a match I need to overwrite the information:

oleDataReader.GetString(0) = ”Something New”
oleDataReader.GetString(1) = ”Something New”
oleDataReader.GetString(2) = ”Something New”
oleDataReader.GetString(3) = ”Something New”

I know that i should not use GetString but some thing like WriteString!

I also need a code to go to the end of the data and inset these information:

oleDataReader.GetString(0) = ”Something New”
oleDataReader.GetString(1) = ”Something New”
oleDataReader.GetString(2) = ”Something New”
oleDataReader.GetString(3) = ”Something New”

I know that i should not use GetString but some thing like WriteString!

I hope there is someone that could give med some code to look at. I am new at this and I am taking classes in C#, but I am working on a little projekt of my own!

You can't update the database using OleDbDataReader or any other DbDataReader subclass. They provide forward-only, read-only access to data. You need something else.

There's more than one way to do this. Here's one:

This approach only requires you to write the SELECT statement; follow the links for more information on how to use these classes.

See also the System.Data.OleDb and System.Data namespace documentation.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.