I want to print one colum of the database, we'll call it foo, to a richtextbox, and then match the input in a textbox the user inputs to it. Any suggestions?

public partial class Form1 : Form
    {
        public Form1()
        {

            InitializeComponent();
  
       
            string connect = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\\linux trivia.accdb";
            OleDbConnection cons = new OleDbConnection(connect);
            cons.Open();
            OleDbCommand cmd = cons.CreateCommand();
            OleDbCommand cmd1 = cons.CreateCommand();
            cmd.CommandText = "SELECT Question FROM questions ORDER BY Question #";
            cmd.CommandText = "Update Question FROM questions";
            OleDbDataReader reader = cmd.ExecuteReader();
            rtb1.Text = Convert.ToString(reader);
            cons.Close();
           
    

        }

Lets break down what you have to do

I want to print one colum of the database, we'll call it foo, to a richtextbox, and then match the input in a textbox the user inputs to it. Any suggestions?

I can see

So you want to get a list all the rows from in the column called Question.

#
OleDbDataReader reader = cmd.ExecuteReader();
rtb1.Text = Convert.ToString(reader);

You are on the right track with this but, you wanna do a reader.Read() and envelope that in a while loop

while(reader.Read())
{
     rtb1.Text += Convert.ToString(reader) + "\n"; // the "\n" will make a new line for each row.
}

This will populate your richtextBox.

Before I go further I want to ask if you are doing this for yourself or an assignment? because there is an easier way to get the results you want than comparing the textbox to rows of text in a richtextbox.

another thing I noticed is

cmd.CommandText = "SELECT Question FROM questions ORDER BY Question #";
cmd.CommandText = "Update Question FROM questions";

dont you want it to be cmd and cmd1?

Your Update statement is wrong but I will get to that later.

Edited 6 Years Ago by finito: n/a

It is for myself. It says that The 'Microsoft.Jet.OLEDB.4.0' provider is not registered on the local machine. Yet I have a legal copy of Microsoft Access 2007 installed. And really what I want to do is to get it to list the first value in the questions field.

string connect = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source="+ Directory.GetCurrentDirectory() +"\\linux trivia.accdb;Persist Security Info=False;";

OleDbConnection cons = new OleDbConnection(connect);

cons.Open();

rtb1.text = new OleDbCommand("SELECT Question FROM questions ORDER BY Question #").ExecuteScaler().toString();

Edited 6 Years Ago by finito: n/a

This article has been dead for over six months. Start a new discussion instead.