0
 string SQL = "SELECT * FROM Email ";
 string myConnString = @"Provider=Microsoft.Jet.OLEDB.4.0;" +
              "Data Source=" + textBox1.Text;
 OleDbConnection myConnection = new OleDbConnection(myConnString);
 OleDbCommand myCommand = new OleDbCommand(SQL, myConnection);
 myConnection.Open();
 OleDbDataReader myReader = myCommand.ExecuteReader();
 if (myReader.Read())
 {
    View.Items.Add(myReader.Read());
 }
 myConnection.Close();

The output is False .The output should be israel.nahum(from the DB)

3 Answers 3

2

You need to specify which column you want to retrieve the text from:

string SQL = "SELECT * FROM Email ";
    string myConnString = @"Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" + textBox1.Text;
    OleDbConnection myConnection = new OleDbConnection(myConnString);
    OleDbCommand myCommand = new OleDbCommand(SQL, myConnection);
    myConnection.Open();
    OleDbDataReader myReader = myCommand.ExecuteReader();

    //Changed if(myReader.Read()) to while(myReader.Read())
    while(myReader.Read())
    {
        View.Items.Add(myReader["NameOfColumnGoesHere"]);
    }



    myConnection.Close();

Take a look at the documentation for the OleDbDataReader Class.

Sign up to request clarification or add additional context in comments.

1 Comment

@Israel, See above edit. Calling myReader.Read() advances to the first record. You want to read until all the records have been read, so you need to use while(myReader.Read()).
1

Read get you access to the iterator (put the next item of the results in it) use

if (myReader.Read())
{
    View.Items.Add(myReader["COLUMN_NAME"]);
}

And so then, if the reader returns something then it'll put in on your item.

2 Comments

View.Items.Add(myReader["EMAIL"]);
I suggest to study first about what you're are trying to do. If you use if(myReader.Read()) then that code will evaluate just ONE time, for the first record. If you want it to perform for EACH record, then use WHILE
0

Please look in MSDN documentation how to use the DataReader object. the Read is reading a row and returning true if there is any row available, you should use other methods to get the values from the current row.

also, notice that you do not need to do a SELECT * FROM... if you only need one column, just do SELECT Email FROM ... for example...

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.